当您在xaml中创建网格时,您可以定义RowDefinitions
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我需要在代码中做同样的事情.我知道我可以写
RowDefinition row = new RowDefinition();
row.Height = new GridLength(1.0, GridUnitType.Star);
Run Code Online (Sandbox Code Playgroud)
但这并没有帮助我,因为我有一个字符串进来.我可能会创建自己的"字符串到GridLength"转换器,但这感觉不对,因为它从xaml工作如此顺利.当然,我尝试了以下但是它不起作用
row.Height = new GridLength("*");
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?