Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Last active July 31, 2020 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfversluis/b90f424e57c111e2559b55248a3d25a0 to your computer and use it in GitHub Desktop.
Save jfversluis/b90f424e57c111e2559b55248a3d25a0 to your computer and use it in GitHub Desktop.
Bindable RowDefinitions in Xamarin.Forms Grid
// MainPage.xaml.cs
public RowDefinitionCollection MyRows => new RowDefinitionCollection() {
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = 100 },
new RowDefinition { Height = GridLength.Star },
new RowDefinition { Height = 50 },
};
public MainPage()
{
InitializeComponent();
BindingContext = this;
}
// MainPage.xaml
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TestSwitch.MainPage">
<Grid RowDefinitions="{Binding MyRows}">
<Frame Grid.Row="0" BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<Label Text="Welcome to Xamarin.Forms!" HorizontalTextAlignment="Center" TextColor="White" FontSize="36" />
</Frame>
<Label Text="1" Grid.Row="1" />
<Label Text="2" Grid.Row="2" />
<Label Text="3" Grid.Row="3" />
</Grid>
</ContentPage>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment