Sizing WPF controls to an exact percentage

℡╲_俬逩灬. 提交于 2021-02-05 05:39:25

问题


In WPF, I want set a controls width to be, say, 97% of it's Parent controls ActualWidth property. How can I do this?


回答1:


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



来源:https://stackoverflow.com/questions/1954533/sizing-wpf-controls-to-an-exact-percentage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!