Ili*_*lov 9 c# xamarin xamarin.forms
我知道你可以这样在XAML中用"*"设置行高:
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
Run Code Online (Sandbox Code Playgroud)
但是C#中的相同表达式返回错误:
new RowDefinition { Height = new GridLength("*", GridUnitType.Auto) },
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何在C#中将网格的行高设置为"*"?
Rui*_*nho 19
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 };
Run Code Online (Sandbox Code Playgroud)