1

I have seen offhand comparisons of WPF to web development in remarks such as (I paraphrase) "web developers will find the WPF style paradigm familiar". Is it possble to specify control sizes as percentages of their container's dimension? If so, in WPF XAML , how would one tell a control to take 50% of its container's width even if the container's width changes?

   <Style TargetType="{x:Type foo:Widget}">
       ?
   </Style>
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Tim
  • 8,669
  • 31
  • 105
  • 183

1 Answers1

2

You could define a grid with 3 columns, the outer two defined to fill the remaining space equally and the middle to 50%:

<Grid>
    <Grid.ColumnDefinitions>
       <ColumnDefinition Width="*"/>
       <ColumnDefinition Width="0.5*"/>
       <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
...
</Grid>

Then add the controls with:

<Button Grid.Column="1" HorizontalAligment="Stretch" />
cguedel
  • 1,092
  • 1
  • 14
  • 28
  • Thanks for this idea. Can the middle column contain a StackPanel? What does the asterisk do in "0.5*"? Does that mean "dynamically resize?" – Tim Jun 02 '13 at 13:48
  • Yeah, de middle column can contain anything you want. About the 0.5*, see here: http://stackoverflow.com/questions/6956832/what-does-asterisk-mean-in-a-wpf-columndefinition – cguedel Jun 02 '13 at 17:41