如何强制 WPF(弹出)窗口在可见之前调整大小?

发布于 2024-11-27 17:09:43 字数 328 浏览 2 评论 0原文

我在 WPF 应用程序中使用弹出窗口。这是一个无边框窗口,SizeToContent 设置为 WidthAndHeight

每次我向用户显示它时,它都会调整自己的大小,以便适应按钮上不同长度的标题和可能变化的按钮数量等。

不幸的是,这种自动调整大小是显而易见的 - 特别是当窗口缩小时;它看起来“跳跃”,因此有点业余。

我从来没有处理这个窗口 - 只是隐藏并再次显示 - 因为我每次都必须重新附加一些事件处理程序,并且还重新填充列表框(带有语言代码),我不确定我应该这样做。

有什么方法可以告诉它在显示之前计算正确的尺寸吗?

I'm using a pop-up window in my WPF application. It's a borderless window with SizeToContent set to WidthAndHeight.

It resizes itself every time I show it to the user in order to accomodate for various lengths of caption on the button and the number of buttons which can vary etc.

Unfortunately, this auto-resizing is noticeable - especially when the window shrinks; it looks "jumpy" and thus sort of amateurish.

I'm never disposing of this window - just hiding and showing again - because I'd have to reattach some event handlers every time, and also repopulate a listbox (with language codes), which I'm not sure I should do.

Is there any way I could tell it to calculate the right size before it is displayed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

じ违心 2024-12-04 17:09:43

一定是WPF性能优化。事先调用 InvalidateMeasure() 可能会有所帮助。

It must be WPF perf optimization. Calling InvalidateMeasure() beforehands might help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文