#1,044 – Placing More than One Element in a Grid Cell

There is nothing to prevent you from placing more than one element within a given cell in a Grid.  In the example below, the Button and the Label share the same cell.

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

        <Button Content="Push Me" Width="100" />
        <Label Content="Oops I'm in the same cell with a button !" />
    </Grid>

1044-001

By default, controls that share the same Grid cell are layered in the order in which they are added to the Grid.  Elements added earlier appear below elements added later.

If we reverse the order of the Button and Label elements in XAML, listing the Label first, it will appear under the Button.

1044-002

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #1,044 – Placing More than One Element in a Grid Cell

  1. Pingback: Dew Drop – April 4, 2014 (#1758) | Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: