WPF 的度量大小约束如何工作?

发布于 2024-10-12 13:49:27 字数 435 浏览 4 评论 0原文

我实现了一个 GUI 系统,其很大程度上受到 WPF 游戏的测量和排列布局系统的启发。虽然它与 DockPanels 和 StackPanels 配合得很好,但我最近需要使用 WrapPanels。我发现,在目前的状态下,我的 GUI 系统无法支持换行,因为我需要知道基于祖先的最大可用大小,而我的测量当前是在没有该信息的情况下完成的。

我检查了 WPF 文档,发现他们的 Measure 方法采用大小约束作为参数:Size Measure(Size availableSize)。这让我很困惑。根据我的理解,WPF首先进行从叶子到根的测量,然后从根到叶子的排列。然而,在这种情况下,在测量阶段需要来自祖先的可用尺寸。这对我来说似乎是矛盾的,因为祖先的大小取决于他们后代的大小。

WPF 如何在测量过程中提供此 availableSize 值?

I've implemented a GUI system heavily inspired by WPF's Measure and Arrange layout system for a game. Although it works fine with DockPanels and StackPanels, I've recently needed to use WrapPanels. I discovered that, in its present state, my GUI system cannot support wrapping because I would need to know the maximum available size based on the ancestors, and my measurement is currently done without that information.

I've checked the WPF documentation and found out that their Measure method takes a size constraint as a parameter: Size Measure(Size availableSize). This puzzles me. From my understanding of it, WPF first does measurement from the leaves to the root and then the arrangement from the root to the leaves. However, in this instance, the available size from the ancestors is needed while in the measurement phase. This seems contradictory to me as the size of the ancestors depend on the size of their descendants.

How does WPF provide this availableSize value in the measurement pass?

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

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

发布评论

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

评论(1

痕至 2024-10-19 13:49:27

我认为您对重新测量的理解是不正确的-它是从根到叶而不是从叶到根发生的。事实上,父控件有责任在其自己的测量过程中对其子控件调用 Measure()。因此,父级可以计算出有多少空间可供子级使用,并且可以在测量时传递该空间。

I think your understanding re measurement is incorrect - it occurs from root to leaves rather than leaves to root. Indeed, it is the parent control's responsibility to call Measure() on its children during its own measure pass. Thus, the parent can figure out how much space is available for its children and it can pass that in when measuring.

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