Skip to content

Instantly share code, notes, and snippets.

@devlights
Created May 25, 2015 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devlights/9e0ec710a0629c9d80c0 to your computer and use it in GitHub Desktop.
Save devlights/9e0ec710a0629c9d80c0 to your computer and use it in GitHub Desktop.
WPFFollowPopup (PlacementTargetに追随するポップアップ)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Interactivity;
namespace DraggablePopup
{
public class FollowPopupBehavior : Behavior<Popup>
{
protected override void OnAttached()
{
base.OnAttached();
var w = Window.GetWindow(AssociatedObject);
w.LocationChanged += w_LocationChanged;
}
protected override void OnDetaching()
{
var w = Window.GetWindow(AssociatedObject);
w.LocationChanged -= w_LocationChanged;
base.OnDetaching();
}
void w_LocationChanged(object sender, EventArgs e)
{
var offset = AssociatedObject.HorizontalOffset;
AssociatedObject.HorizontalOffset = offset + 1;
AssociatedObject.HorizontalOffset = offset;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment