Skip to content

Instantly share code, notes, and snippets.

@nodoid
Created July 21, 2017 08:06
Show Gist options
  • Save nodoid/b1f325f578a4fc35b22243f5895cf243 to your computer and use it in GitHub Desktop.
Save nodoid/b1f325f578a4fc35b22243f5895cf243 to your computer and use it in GitHub Desktop.
/* App.ScreenSize is obtained from the platform by DI */
// this code is completely untested!
public class MyGrid : ContentPage
{
public class MyGrid()
{
var grid = new Grid
{
WidthRequest = App.ScreenSize.Width
};
grid.RowDefinitions = new RowDefinitionCollection
{
new RowDefinition {Height = 48},
new RowDefinition {Height = GridLength.Star},
new RowDefinition {Height = 48}
};
grid.ColumnDefinitions = ColumnDefinitionCollection
{
new ColumnDefinition {Width = App.ScreenSize.Width}
};
// create the 1/3 button
var btnOneThirdWidth = new Button
{
HeightRequest = 44,
WidthRequest = App.ScreenSize.Width / 3,
Text = "1/3"
};
// create the 1/4 button
var btnOneQuarterWidth = new Button
{
HeightRequest = 44,
WidthRequest = App.ScreenSize.Width / 4,
Text = "1/4"
};
// create the stacklayouts
var stackThreeButton = new StackLayout
{
Orientation = StackOrientation.Horizontal
BackgroundColor = Color.Wheat,
Children = { btnOneThirdWidth, btnOneThirdWidth, btnOneThirdWidth}
};
var quarterStack = new StackLayout
{
WidthRequest = App.ScreenSize.Width / 4,
Children = {btnOneQuarterWidth}
};
var stackFourButton = new StackLayout
{
Orientation = StackOrientation.Horizontal,
BackgroundColor = Color.Yellow,
Children = {quarterStack, quarterStack, quarterStack, quarterStack}
};
grid.Children.Add(stackThreeButton, 0, 0);
grid.Children.Add(stackFourButton, 0, 2);
Content = grid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment