Skip to content

Instantly share code, notes, and snippets.

@adrianstevens
Created June 6, 2014 22:40
Show Gist options
  • Save adrianstevens/dcd3c18db2a449649e69 to your computer and use it in GitHub Desktop.
Save adrianstevens/dcd3c18db2a449649e69 to your computer and use it in GitHub Desktop.
Xamarin.Forms Grid with headers code snippet
public class GridLayoutPage : ContentPage
{
public GridLayoutPage()
{
var layout = new StackLayout
{
Orientation = StackOrientation.Vertical,
Padding = 20
};
var header = new Grid()
{
ColumnSpacing = 10,
};
for (var i = 0; i < 4; i++)
{
header.ColumnDefinitions.Add(new ColumnDefinition()
{ Width= new GridLength(1, GridUnitType.Star)});
}
header.Children.Add(new Label { Text = "One" }, 0, 0); // Left, First element
header.Children.Add(new Label { Text = "Two" }, 1, 0); // Right, First element
header.Children.Add(new Label { Text = "Three" }, 2, 0); // Left, Second element
header.Children.Add(new Label { Text = "Four" }, 3, 0); // Right, Second element
var grid = new Grid
{
RowSpacing = 10
};
for (var i = 0; i < 4; i++)
{
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
}
for (int j = 0; j < 400; j++)
{
grid.Children.Add(new Label {Text = "item " + j}, j%4, j/4);
}
layout.Children.Add(header);
layout.Children.Add(new ScrollView { Content = grid, VerticalOptions = new LayoutOptions(LayoutAlignment.Fill, true)});
Content = layout;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment