Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I know that you can set the row height with a "*" in XAML this way:

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

but the same expression in C# returns an error:

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

So my question is how to set the row height of a grid to a "*" in C#?

like image 876
Ilia Stoilov Avatar asked Aug 14 '15 08:08

Ilia Stoilov


1 Answers

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 };  

Screenshot of the above layout on iOS

like image 149
Rui Marinho Avatar answered Sep 27 '22 20:09

Rui Marinho