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