#407 – Grid Contains Single Row and Column by Default

If you define a Grid, but do not define any rows or columns using the RowDefinitions and ColumnDefinitions properties, the resulting grid will contain a single row and a single column.

    <Grid>
        <Button Content="I'm in a Grid" Margin="5"/>
    </Grid>


Similarly, if you define a Grid and specify multiple columns using the ColumnDefinitions property, but not the RowDefinitions property, you’ll get a single row and the specified number of columns.  (The same is true for a single column and explicit number of rows).

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <Label Grid.Column="0" Content="Larry" Margin="10" Background="Lavender"/>
        <Label Grid.Column="1" Content="Moe" Margin="10" Background="Magenta"/>
        <Label Grid.Column="2" Content="Curly" Margin="10" Background="Cornsilk"/>
    </Grid>



Advertisements

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

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 )

Google+ photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

%d bloggers like this: