Created
May 25, 2015 15:04
-
-
Save devlights/9e0ec710a0629c9d80c0 to your computer and use it in GitHub Desktop.
WPFFollowPopup (PlacementTargetに追随するポップアップ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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