有没有办法在显示 WPF 窗口之前确定其宽度和高度?
我正在尝试将 WPF 窗口置于鼠标光标当前位置的中心。获取鼠标坐标没有问题,但我需要确定窗口的宽度和高度,以便计算设置“Left”和“Top”属性的偏移量。
有没有办法在显示窗口之前确定窗口的宽度和高度(调用“Show”方法)?
我在窗口上将“SizeToContent”设置为 true,以便内容决定实际的窗口大小。我已经尝试过调用“Measure”并期望它设置“DesiredSize”,但事实并非如此。
I am trying to center a WPF Window on the current position of the mouse cursor. Getting the mouse coordinates is no problem, but I need to determine the width and height of the window in order to calculate the offset for setting the 'Left' and 'Top' properties.
Is there a way to determine the width and height of a window before showing it (calling the 'Show' method)?
I have 'SizeToContent' set to true on my window so that the content determines the actual window size. I have already tried calling 'Measure' and was expecting this to set 'DesiredSize' but it didn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不先调用 Show() 然后将其置于鼠标光标当前位置的中心呢?
Why not call Show() first and then center it on the current position of the mouse cursor?