How layout works
A layout container asks each child how much space it wants, then gives it a rectangle. Understanding those two steps helps explain why a control stretches, clips, or disappears.
Measure first, arrange second
Measure(available, context) returns the desired margin-box size. Arrange(rect, context) chooses the final position and size. Core's view shell applies margins, minimum/maximum dimensions, alignment, and cached layout bookkeeping around your MeasureCore and ArrangeCore overrides.
An available size is a constraint, not always the final allocation. Some containers offer unbounded space in one axis: VerticalStack measures children with unlimited height, while HorizontalStack offers unlimited width. A child should not blindly return infinity as a meaningful desired size.
Distinguish the three spaces
- Margin belongs outside a view. It separates the view from its neighbors or the container edge.
- The view frame is the arranged rectangle used by layout and drawing.
- Padding belongs to a container such as
BorderorCard. It separates the container's outline/background from its content.
Not every view has a padding property. Add a Border around content when you need an explicit inset.
A small constructor-body example:
var panel = new Xui.Core.UI.Border
{
Margin = 16,
Padding = 24,
BackgroundColor = new Xui.Core.Canvas.Color(0xEADCFBFF),
Content = new Xui.Core.UI.Label { Text = "Room to breathe", FontSize = 18 }
};
The outer 16-unit margin is not painted by the border. The inner 24-unit padding is part of the border's painted box and leaves room around the label.
Choose alignment and limits deliberately
HorizontalAlignment and VerticalAlignment control how a view uses its allocation. Stretch fills the offered dimension; Center or Middle uses the desired size and positions it within the allocation. Minimum and maximum dimensions constrain the measured size, but do not replace the parent's layout policy.
For an exact-sized control, matching minimum and maximum dimensions can express its intended size. For an adaptive page, prefer constraints and container layout to a hardcoded screen-sized rectangle.
Property changes that affect text or geometry need a measure/layout invalidation. Color-only changes generally need rendering. Many Core setters perform this automatically; extra layout properties and some plain properties require an explicit Invalidate() after a runtime change.
Inspect Grid layouts for a layout that reserves fixed header space and distributes the remaining area.