/// A behavior that forces the associated popup to update its position when the <see cref="Popup.PlacementTarget"/>
/// location has changed.
public class AutoRepositionPopupBehavior : Behavior<Popup>
public Point StartPoint = new Point(0, 0);
public Point EndPoint = new Point(0, 0);
protected override void OnAttached()
if (AssociatedObject.PlacementTarget != null)
AssociatedObject.PlacementTarget.LayoutUpdated += OnPopupTargetLayoutUpdated;
void OnPopupTargetLayoutUpdated(object sender, EventArgs e)
public void ResetPopUp()
// The following trick that forces the popup to change it's position was taken from here:
Random random = new Random();
AssociatedObject.PlacementRectangle = new Rect(new Point(random.NextDouble() / 1000, 0), new Size(7, 25));
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)