开发者

WPF - Resizing Children to Fill a Parent

In WPF, I simply want to have a 'container' which has 3 textblocks. I would li开发者_StackOverflow社区ke 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜