4

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

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
will
  • 3,975
  • 6
  • 33
  • 48

1 Answers1

9

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

Anvaka
  • 15,658
  • 2
  • 47
  • 56