.NET MAUI Documentation

StackLayout

The StackLayout is a layout container that arranges its child elements in a one-dimensional line, either horizontally or vertically. It's a fundamental and widely used layout in .NET MAUI for arranging controls in sequence.

Orientation

By default, StackLayout arranges its children vertically. You can change this behavior by setting the Orientation property:

Spacing

The Spacing property controls the amount of space between child elements within the StackLayout. This value is a density-independent pixel value.

Example Usage

Vertical StackLayout

<StackLayout Padding="10,0,10,0"
                   Spacing="10"
                   VerticalOptions="Center"
                   HorizontalOptions="Center">
    <Label Text="Welcome to .NET MAUI!"
           FontSize="24"
           TextColor="DarkBlue"/>
    <Button Text="Get Started"/>
    <Image Source="dotnet_bot.png"/>
</StackLayout>

Horizontal StackLayout

<StackLayout Orientation="StackOrientation.Horizontal"
                   Spacing="20"
                   Padding="10">
    <Image Source="icon_heart.png" HeightRequest="50"/>
    <Label Text="Love .NET MAUI"
           VerticalOptions="Center"
           FontSize="18"/>
</StackLayout>

Properties Summary

Best Practices

Performance Considerations

While StackLayout is efficient for most use cases, excessively deep nesting of StackLayouts can lead to performance degradation. In such scenarios, consider refactoring your layout using Grid or a single StackLayout with more sophisticated child element arrangement.