WPF 布局以 2 为增量重复调用 MeasureOverride?
我遇到过这样的情况:我有一个自定义面板(继承自面板),并且我将其用作 ListView 中的 ItemsPanel。
当我调整其所在容器的大小时,如果我将其调整得更小,我的面板的 MeasureOverride 函数将被调用一次,但如果我将其大小调整得更大(假设从 100 到 300),它会对 100 到 300 之间的每个值调用 MeasureOverride 和 ArrangeOverride ,以 2 为增量(即 102、104 等)。
奇怪的是容器立即调整大小(其大小立即变为 300)。
我从 MeasureOverride 返回什么似乎并不重要 - 它只是这样做。
我希望我可以在一个非常小的应用程序中实现它并将其发布在这里,但我还无法像那样重现它。不过,我可以在我的应用程序中重现它一整天。
有谁知道这可能是什么原因造成的?
I've run into a case where I have a custom Panel (inherits from Panel) and I'm using it as an ItemsPanel in a ListView.
When I resize the container that it's in, if I resize it smaller, my panel's MeasureOverride function gets called once, but if I resize it larger (let's say from 100 to 300), it calls MeasureOverride and ArrangeOverride for every value between 100 and 300, in increments of 2 (so 102, 104, etc.).
The weird thing is that the container resizes right away (its size gets to 300 immediately).
It doesn't seem to matter what I return from MeasureOverride - it just does this.
I wish I could make it happen in a really small application and post it here, but I haven't been able to reproduce it like that yet. I can reproduce it all day in my app though.
Does anyone know what could cause this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可以通过动态设置面板的 MinWidth 属性来解决此问题,使其随容器的大小而变化。这可以防止不必要的 MeasureOverride 调用。我仍然有点不确定为什么会发生这种情况。
I was able to get around this behavior by dynamically setting the MinWidth property of my panel such that it changed with the size of the container. This prevented the unnecessary calls to MeasureOverride. I'm still a bit uncertain why it was happening though.