Question

How can I determine the placement (PlacementMode) of a Popup control relative to it's target after it has been drawn to the screen? I am noticing that though I set the Placement of my Popup to Bottom, when there is little room left on the screen it chooses to invert the Placement. This is all well and fine, providing there is a method of retrieving the updated Placement. So far, checking the Placement seems to return the actual value that I set, and the vertical and horizontal offsets are both 0.0.

Was it helpful?

Solution

When you set the PlacementMode you are suggesting where you would like the popup to appear in relation to the PlacementTarget, PlacementRectangle or by default it's parent. The Popup can't be drawn outside of they bounds of the screen for security.

Reference on popup placement:

http://msdn.microsoft.com/en-us/library/bb613596.aspx

If you want to better control how your Popup renders when encountering the edge of the screen could specify a Custom Popup Position.

As described here:

http://msdn.microsoft.com/en-us/library/ms743607.aspx

This lets you specify the primary offset and alignment and a secondary one if the first is not available. When there is a conflict it chooses the placement that displays the largest portion of the Popup.

If you really need the coordinates of your Popup this post has a win32 trick you can use to get the exact location of your popup.

WPF Popup Control - Find X, Y Coordinates

But you should be able to solve most layout issues by specifying a custom position.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top