Explain the measure and arrange layout cycle in MAUI.
Short 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).
Advertisement
AModel 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.
Likely follow-ups
- How do you write a custom layout? | Why avoid deep view nesting?
Related topics