【发布时间】:2014-01-09 21:41:52
【问题描述】:
我在 XAML 中有下一个代码:
<Grid.RowDefinitions>
<RowDefinition Height="6*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
我想要的是修改 C# 中的代码。我正在使用下一个代码:
ListBoxGrid.RowDefinitions[0].Height = new GridLength(100);
ListBoxGrid.RowDefinitions[1].Height = new GridLength(800);
使用像素来设置行的高度效果很好,但我非常想使用“*”-thing,比如
ListBoxGrid.RowDefinitions[0].Height = "*";
ListBoxGrid.RowDefinitions[1].Height = "3*";
我怎么能做这样的事情?我在想一个解决方案是获取包含我的网格的控件/页面的高度并制作:
ListBoxGrid.RowDefinitions[0].Height = ControlHeight/4;
ListBoxGrid.RowDefinitions[1].Height = ControlHeight/4*3;
还有其他解决方案吗?比这些操作更优雅? (我将使用两行以上,所以最好不要有非常复杂的东西)。
【问题讨论】: