在运行时获取组合框弹出窗口的大小
我正在尝试获取 Silverlight ComboBox 下拉窗口的宽度和高度。 不幸的是 ActualWidth
和 ActualHeight
始终返回 0。
I am trying to get the width and height of a Silverlight ComboBox's dropdown window.
Unfortunately ActualWidth
and ActualHeight
are returning 0 always.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
但这不是一个好方法。
But it's not a good way.
如果不实际渲染弹出窗口,您就无法获得实际大小。这意味着如果弹出窗口隐藏,ActualSizes 将为 0。这是 WPF 为您执行布局和渲染逻辑的结果。
您可以通过执行 Measure< 来获取弹出窗口请求的高度/a> 传递弹出窗口本身。如果尚未创建弹出窗口,那么您仍然遇到麻烦。 (并且它可能直到第一次显示才被创建。)
You can't get the actual size without actually rendering the popup. This implies that ActualSizes will be 0 if the popup is hidden. This is a consequence of WPF performing layout and rendering logic for you.
You could possibly get the popup's requested height by performing a Measure pass on the popup itself. If the popup hasn't been created yet, you're still in trouble though. (And it may not get created until the first time it's displayed.)
我自己找到了一个解决方案:您必须在测量之前将弹出窗口的“IsOpen”设置为 true,然后将其设置回 false。这是我让它发挥作用的唯一方法。
I found a solution to this by myself: you have to set the popup's "IsOpen" to true before measuring, and then set it back to false. It's the only way I could make it work.