[This documentation is preliminary and is subject to change.]
Provides the behavior for the "Measure" pass of the layout cycle. Classes can override this method to define their own "Measure" pass behavior.
Syntax
Parameters
- availableSize
-
Type: Size
The available size that this object can give to child objects. Infinity can be specified as a value to indicate that the object will size to whatever content is available.
Return value
Type: Size
The size that this object determines it needs during layout, based on its calculations of the allocated sizes for child objects or based on other considerations such as a fixed container size.
Examples
This example implements MeasureOverride to customize the "Measure" pass logic for a custom panel implementation. Note in particular these aspects of the code:
-
Iterates over children.
-
For each child, calls Measure, using a Size that makes sense based on how the panel logic treats the number of children and its own known size limit.
-
Returns its size (in this case, this simple panel returns a fixed size rather than a size calculated on accumulating the measurements).
// First measure all children and return available size of panel protected override Size MeasureOverride(Size availableSize) { // Measure first 9 children giving them space up to 100x100, remaining children get 0x0 int i = 0; foreach (FrameworkElement child in Children) { if (i < 9) { child.Measure(new Size(100, 100)); } else { child.Measure(new Size(0, 0)); } i++; } // return the size available to the whole panel, which is 300x300 return new Size(300, 300); }
Requirements
|
Minimum supported client | Windows 8 Release Preview |
|---|---|
|
Minimum supported server | Windows Server 2012 |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 5/22/2012
