2015-08-14 20 views
5

So che è possibile impostare l'altezza della riga con un "*" in XAML questo modo:Xamarin Forms Grid - Altezza riga di "*" in C#?

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

ma la stessa espressione in C# restituisce un errore:

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

Quindi la mia domanda è come impostare l'altezza della riga di una griglia su "*" in C#?

risposta

12
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

+1

Grazie, e come posso fare l'ultima fila di estendere alla parte inferiore del layout non importa quale sia il contenuto della riga è? –

Problemi correlati