When the content of a Window object is rendered, the layout system is automatically invoked. In order to display content, the Content of the window must define a root Panel which serves to define a framework by which Children are organized on the screen. See Panel Elements and Custom Layout Behaviors for a list of available Panel elements and information on creating custom layout elements.
The first pass of layout is the measure pass, wherein each member of the Children collection is evaluated. The process begins with a call to the Measure method. This method is called within the implementation of the parent Panel element, and does not need to be called explicitly for layout to occur.
First, native size properties of the UIElement are evaluated, such as Clip and Visibility. This generates a value called constraintSize which is passed to MeasureCore.
Secondly, framework properties defined on FrameworkElement are processed, affecting the value of constraintSize. These properties tend to describe the sizing characteristics of the underlying UIElement, such as its Height, Width, Margin, and Style. Each of these properties can alter the space necessary to display the element. MeasureOverride is then called with constraintSize as a parameter.
Note: |
|---|
There is a difference between the properties of Height and Width and ActualHeight and ActualWidth. For example, the ActualHeight property is a calculated value based on other height inputs and the layout system. The value is set by the layout system itself, based on an actual rendering pass, and may therefore lag slightly behind the set value of properties such as Height that are the basis of the input change. Because ActualHeight is a calculated value, you should be aware that there could be multiple or incremental reported changes to it as a result of various operations by the layout system. The layout system may be calculating required measure space for child elements, constraints by the parent element, and so on. |
The ultimate goal of the measure pass is for the child to determine its DesiredSize, which happens during the MeasureCore call. This value is stored by Measure for use during the content arrange process.
The arrange process begins with a call to the Arrange method. During the arrange pass, the parent Panel element generates a rectangle that represents the bounds of the child. This value is passed to the ArrangeCore method for processing.
The ArrangeCore method evaluates the DesiredSize of the child and evaluates any additional margins that may affect the rendered size of the element and generates an arrangeSize, which is passed on to the ArrangeOverride of the Panel as a parameter. ArrangeOverride generates the finalSize of the child, and finally the ArrangeCore method does a final evaluation of offset properties such as margin and alignment and places the child within its layout slot. The child does not need to (and frequently won't) fill the entire allocated space. Control is then returned to the parent Panel, and the layout process is complete.