开发者

Sizing WPF controls to an exact percentage

开发者 https://www.devze.com 2022-12-14 14:48 出处:网络
In WPF, I want set开发者_如何学C a controls width to be, say, 97% of it\'s Parent controls ActualWidth property.How can I do this?You can use Grid panel. E.g:

In WPF, I want set开发者_如何学C a controls width to be, say, 97% of it's Parent controls ActualWidth property. How can I do this?


You can use Grid panel. E.g:

<Border>
  <Grid>  
    <Grid.ColumnDefinitions>
     <ColumnDefinition Width="0.97*"/>
     <ColumnDefinition Width="0.03*"/>
    </Grid.ColumnDefinitions>
    <Button Content="97%"/>
    <Border Grid.Column="1" Background="Green">
   </Border>
  </Grid>
</Border>

Grid will occupy 100% of available border's size. First column will use 97% of it. And the rest 3% are given to border in the second column.

Hope this helps.

Cheers, Anvaka

0

精彩评论

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

关注公众号