我有一个如下网格,
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.5*" />
<RowDefinition Height="0.5*" />
</Grid.RowDefinitions>
</Grid>
如何在代码中提供Height = "0.5*"
?
答案 0 :(得分:69)
您可以使用:
rowDefinition.Height = new GridLength(0.5, GridUnitType.Star);
答案 1 :(得分:17)
grid.RowDefinitions[0].Height = new GridLength(0.5, GridUnitType.Star);