How does WPF's measure size constraint work?
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 av开发者_如何学Pythonailable 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?
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.
精彩评论