Grid Control

The Grid panel arranges child elements in rows and columns, providing a flexible layout system for WinUI applications.

Definition

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="2*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
</Grid>

Properties

PropertyTypeDescription
RowDefinitionsRowDefinitionCollectionDefines the rows of the grid.
ColumnDefinitionsColumnDefinitionCollectionDefines the columns of the grid.
ShowGridLinesboolShows the grid lines at runtime (useful for debugging).
BackgroundBrushBackground brush for the panel.

Methods

Examples

XAML
C# Code‑Behind
<Grid ShowGridLines="True">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="2*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <TextBlock Text="Header" Grid.Row="0" Grid.ColumnSpan="2"
               FontSize="24" HorizontalAlignment="Center"/>

    <ListView Grid.Row="1" Grid.Column="0"/>
    <StackPanel Grid.Row="1" Grid.Column="1" Margin="8">
        <Button Content="Add"/>
        <Button Content="Remove" Margin="0,8,0,0"/>
    </StackPanel>
</Grid>

Remarks

Use Auto, * (star sizing), or a fixed value for row and column sizes. Star sizing distributes remaining space proportionally.

Nested grids are common for complex layouts. Keep the visual tree shallow when possible to improve performance.