确定弹出窗口相对于目标的位置
在将 Popup 控件绘制到屏幕后,如何确定 Popup 控件相对于其目标的位置 (PlacementMode)?我注意到,虽然我将弹出窗口的位置设置为底部,但当屏幕上只剩下很少的空间时,它会选择反转位置。一切都很好,只要有一种方法可以检索更新后的放置。到目前为止,检查 Placement 似乎返回了我设置的实际值,并且垂直和水平偏移均为 0.0。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您设置 PlacementMode 时,您会建议您希望弹出窗口相对于 PlacementTarget、PlacementRectangle 或默认情况下其父级出现的位置。为了安全起见,不能将弹出窗口绘制到屏幕边界之外。
有关弹出窗口放置的参考:
http://msdn.microsoft.com/en-us /library/bb613596.aspx
如果您想更好地控制弹出窗口在遇到屏幕边缘时的呈现方式,可以指定自定义弹出窗口位置。
如此处所述:
http://msdn.microsoft.com/en-us/ library/ms743607.aspx
这使您可以指定主要偏移和对齐方式,如果第一个偏移和对齐方式不可用,则指定次要偏移和对齐方式。当存在冲突时,它会选择显示弹出窗口最大部分的位置。
如果您确实需要弹出窗口的坐标,这篇文章有一个 win32 技巧,您可以使用它来获取弹出窗口的确切位置。
WPF 弹出控件 - 查找 X、Y 坐标
但是你应该能够解决通过指定自定义位置来解决大多数布局问题。
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.