Panelelements enable many complex layouts. For example, stacking elements can easily be achieved by using the
StackPanelelement, while more complex and free flowing layouts are possible by using a
Panelis an abstract class and laying out multiple controls to fill the available space is usually done with a
Gridwith no rows/columns. In Avalonia
Panelis a usable control that has the same layout behavior as a
Gridwith no rows/columns, but with a lighter runtime footprint.
Controlconsumed by the layout system can be thought of as a rectangle that is slotted into the layout. The
Boundsproperty returns the boundaries of an element's layout allocation. The size of the rectangle is determined by calculating the available screen space, the size of any constraints, layout-specific properties (such as margin and padding), and the individual behavior of the parent
Panelelement. Processing this data, the layout system is able to calculate the position of all the children of a particular
Panel. It is important to remember that sizing characteristics defined on the parent element, such as a
Border, affect its children.
Childrencollection. Layout is an intensive process. The larger the
Childrencollection, the greater the number of calculations that must be made. Complexity can also be introduced based on the layout behavior defined by the
Panelelement that owns the collection. A relatively simple
Panel, such as
Canvas, can have significantly better performance than a more complex
Panel, such as
Controlare evaluated, such as
Panel-specific logic is applied, such as
Dockdirection or stacking
Childrencollection is drawn on the screen.
Childrenare added to the collection
Childrencollection, a measure pass and an arrange pass. Each child
Panelprovides its own
ArrangeOverridemethods to achieve its own specific layout behavior.
Childrencollection is evaluated. The process begins with a call to the
Measuremethod. This method is called within the implementation of the parent
Panelelement, and does not have to be called explicitly for layout to occur.
IsVisibleare evaluated. This generates a constraint that is passed to
Control, such as its
Margin. Each of these properties can change the space that is necessary to display the element.
MeasureOverrideis then called with the constraint as a parameter.
Boundsis 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.
DesiredSize, which occurs during the
DesiredSizevalue is stored by
Measurefor use during the content arrange pass.
Arrangemethod. During the arrange pass, the parent
Panelelement generates a rectangle that represents the bounds of the child. This value is passed to the
ArrangeCoremethod for processing.
ArrangeCoremethod evaluates the
DesiredSizeof the child and evaluates any additional margins that may affect the rendered size of the element.
ArrangeCoregenerates an arrange size, which is passed to the
ArrangeOverridemethod of the
Panelas a parameter.
ArrangeOverridegenerates the finalSize of the child. Finally, the
ArrangeCoremethod does a final evaluation of offset properties, such as margin and alignment, and puts the child within its layout slot. The child does not have to (and frequently does not) fill the entire allocated space. Control is then returned to the parent
Paneland the layout process is complete.