Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - Resizing Children to Fill a Parent

In WPF, I simply want to have a 'container' which has 3 textblocks. I would like these 3 textblocks to be sized so they each take up 1/3 of the parent's width. I noticed that the stackpanel sizes the last child automatically, but is there a way to size each child automatically?

like image 908
Peanut Avatar asked Jan 27 '11 19:01

Peanut


1 Answers

Use a Grid or a UniformGrid

<Grid HorizontalAlignment="Stretch">
  <Grid.ColumnDefinitions>
     <ColumnDefinition Width="*" />
     <ColumnDefinition Width="*" />
     <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>
  <TextBlock Text="1" Grid.Column="0"/>
  <TextBlock Text="2" Grid.Column="1"/>
  <TextBlock Text="3" Grid.Column="2"/>

</Grid>

The grid is very common and in every WPF-App used a lot. However also the UniformGrid is very handy but not so well known.

like image 93
HCL Avatar answered Sep 22 '22 22:09

HCL