Xamarin Forms Grid - C# 中“*”的行高?

Xamarin Forms Grid - Row height of "*" in C#?

我知道你可以在 XAML 中用“*”设置行高,方法如下:

 <RowDefinition Height="Auto" />
 <RowDefinition Height="*" />

但是在C#中同样的表达式returns报错:

new RowDefinition { Height = new GridLength("*", GridUnitType.Auto) },

所以我的问题是如何在 C# 中将网格的行高设置为“*”?

var grid = new Grid ();
grid.RowDefinitions.Add (new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add (new RowDefinition { Height = new GridLength (1, GridUnitType.Star) });

var stacklayout1 = new StackLayout { HeightRequest = 100, BackgroundColor = Color.Red };
var stacklayout2 = new StackLayout { BackgroundColor = Color.Blue };

Grid.SetRow (stacklayout2, 1);

grid.Children.Add (stacklayout1);
grid.Children.Add (stacklayout2);

MainPage = new ContentPage { Content = grid };