Ian
Ian

Reputation: 4909

WPF dock control to cell in grid

If I have a 2 by 2 Grid how do I get a button to fill the entire cell? Do I have to use a trigger? How would I get the column's width in that case?

Thanks Ian

Upvotes: 0

Views: 807

Answers (1)

Aaron McIver
Aaron McIver

Reputation: 24713

The Button by default will consume the entire cell.

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Button></Button>
    </Grid>

You can get the columns width by accessing the ColumnDefinitions collection.

Grid g = new Grid();
g.ColumnDefinitions[0].Width;

Upvotes: 1

Related Questions