How to split a Grid row into two columns?

GANI picture GANI · Jan 27, 2012 · Viewed 32.9k times · Source

I have the Grid layout with 3 rows.How do i split the 3rd row into 2 columns.

<Grid.RowDefinitions>
    <RowDefinition Height="0.75*"/>
    <RowDefinition Height="0.25*"/>
    <RowDefinition Height="36"/>
</Grid.RowDefinitions>

Answer

Joe White picture Joe White · Jan 27, 2012

Two ways you can do it:

  • Use nested layouts. Put another Grid in the third row, and have two columns in that sub-grid.

    <Grid>
        <Grid.RowDefinitions> ... </Grid.RowDefinitions>
        <ThingInFirstRow Grid.Row="0" />
        <ThingInSecondRow Grid.Row="1" />
        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <ThingInLowerLeft Grid.Column="0" />
            <ThingInLowerRight Grid.Column="0" />
        </Grid>
    </Grid>
    
  • Stick with one Grid, give it two columns, and make the things in the first two rows span across both columns using ColumnSpan.

    <Grid>
        <Grid.RowDefinitions> ... </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <ThingInFirstRow Grid.Row="0" Grid.ColumnSpan="2" />
        <ThingInSecondRow Grid.Row="1" Grid.ColumnSpan="2" />
        <ThingInLowerLeft Grid.Row="2" Grid.Column="0" />
        <ThingInLowerRight Grid.Row="2" Grid.Column="1" />
    </Grid>