WPF Popup - when to disable, how to keep origin control in relative position?;)

2 simple questions.

Given the WPF popup ...

  • What is a good way to hide it again when used as a submenu? Which event is correct?

  • What is the way to keep a stable position relative to the origin control?

Thanks in advance;)

+2


a source to share


1 answer


  • Events Popup.Opened

    and Popup.Closed

    fire when the popup is shown and hidden.
  • I would install Popup.PlacementRectangle

    based on the source Control

    , which can be obtained with a method Control.PointToScreen

    like this:

Point location = originControl.PointToScreen(new Point(0, 0));



You will need to listen for an event UIElement.LayoutUpdated

(and possibly some other events) to determine when the position of the control has changed.

0


a source







All Articles