46

I have a grid as follows,

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="0.5*" />
        <RowDefinition Height="0.5*" />
    </Grid.RowDefinitions>
</Grid>

How do I give the Height = "0.5*" in code behind?

H.B.
  • 166,899
  • 29
  • 327
  • 400
Aks
  • 5,188
  • 12
  • 60
  • 101

2 Answers2

80

You can use:

rowDefinition.Height = new GridLength(0.5, GridUnitType.Star);
CodeNaked
  • 40,753
  • 6
  • 122
  • 148
21
grid.RowDefinitions[0].Height = new GridLength(0.5, GridUnitType.Star);
publicgk
  • 3,170
  • 1
  • 26
  • 45