Back to results for “Custom Controls”
.NET MAUI › XAML & UI Layouts

Explain the measure and arrange layout cycle in MAUI.

Advanced

Answer

Layout happens in two passes. In Measure, each layout asks children for their desired size given available space. In Arrange, the layout positions each child within the final rectangle it allocates. Custom layouts implement ILayoutManager (Measure and ArrangeChildren). Minimizing invalidations and avoiding deep nesting keeps this cycle cheap.
public class SimpleStackLayoutManager : ILayoutManager
{
    public Size Measure(double widthConstraint, double heightConstraint) { /* ... */ }
    public Size ArrangeChildren(Rect bounds) { /* ... */ }
}
Real-world example A team writes a custom masonry layout by implementing ILayoutManager to place cards of varying heights into balanced columns.

Common follow-ups: How do you write a custom layout? | Why avoid deep view nesting?