| MAUI-StackLayout | MAUI-FlexLayout | |
📐 Layouts in .NET MAUI – Grid |
The Grid is recognized as the most versatile and powerful layout container in .NET MAUI. Unlike one-dimensional layouts like StackLayout, a Grid organizes UI elements into a two-dimensional structure of rows and columns. This allows for complex, pixel-perfect designs that remain responsive across mobile and desktop screens.
The Grid works by defining a set of horizontal rows and vertical columns. Each intersection creates a "cell" where you can place a control such as a Button or Label.
Modern .NET MAUI development prefers Grid for performance and flexibility.
The following example creates a header with an icon on the left and a title that fills the remaining space.
<!-- A Grid with 1 row and 2 columns -->
<Grid ColumnDefinitions="Auto, *"
RowDefinitions="Auto"
ColumnSpacing="10"
Padding="10">
<Image Source="logo.png"
HeightRequest="40"
WidthRequest="40"
Grid.Column="0" />
<Label Text="Welcome to MAUI"
FontSize="20"
VerticalOptions="Center"
Grid.Column="1" />
</Grid>
The Grid is the primary tool for building structured layouts in .NET MAUI. It is ideal for headers, dashboards, calculators, and any interface that requires precise alignment and flexibility.
Grid is a powerful layout in .NET MAUI that arranges child elements into rows and columns. It is useful for creating structured, table-like layouts.
<Grid RowDefinitions="Auto,Auto,*"
ColumnDefinitions="Auto,*">
<Label Text="Username:"
Grid.Row="0" Grid.Column="0" />
<Entry Placeholder="Enter username"
Grid.Row="0" Grid.Column="1" />
<Label Text="Password:"
Grid.Row="1" Grid.Column="0" />
<Entry Placeholder="Enter password" IsPassword="True"
Grid.Row="1" Grid.Column="1" />
<Button Text="Login"
Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" />
</Grid>
RowDefinitions="Auto,Auto,*" → First two rows sized to content, last row takes remaining space.ColumnDefinitions="Auto,*" → First column sized to content, second column fills remaining width.
Grid provides a flexible way to design structured layouts in MAUI.
It is more powerful than StackLayout when you need precise control over positioning.
| MAUI-StackLayout | MAUI-FlexLayout | |