6

I have the following grid, which is loaded inside a StackLayout:

            Grid grid = new Grid {
            VerticalOptions = LayoutOptions.FillAndExpand,
            HorizontalOptions = LayoutOptions.FillAndExpand,
            RowDefinitions = 
            {
                new RowDefinition { Height = new GridLength(40, GridUnitType.Auto) },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = new GridLength(40, GridUnitType.Auto) },
            },
            ColumnDefinitions = 
            {
                new ColumnDefinition { Width = new GridLength(100, GridUnitType.Auto) },
                new ColumnDefinition { Width = new GridLength(100, GridUnitType.Star) },
                new ColumnDefinition { Width = new GridLength(50, GridUnitType.Star) },
                new ColumnDefinition { Width = new GridLength(50, GridUnitType.Star) },
                new ColumnDefinition { Width = new GridLength(100, GridUnitType.Auto) },
            }
        };

        grid.Children.Add (btnMenu, 0, 1, 0, 1);
        grid.Children.Add (lblProfile, 1, 5, 0, 1);
        grid.Children.Add (btnEdit, 4, 5, 0, 1);
        grid.Children.Add (lblFirstName, 1, 2, 1, 2);
        grid.Children.Add (lblFirstNameValue, 2, 3, 1, 2);

        Content = new StackLayout { 
            HorizontalOptions = LayoutOptions.StartAndExpand,
            Children = { 
                grid
            }
        };

I have changed the width values and types of the width of the grid, but I can't make it to fill the whole screen, unless I use fixed values, which will look fine on my phone but really bad on everything else.

Ilia Stoilov
  • 632
  • 2
  • 11
  • 27

2 Answers2

14

Try adding VerticalOptions = LayoutOptions.FillAndExpand to the parent StackLayout

pnavk
  • 4,552
  • 2
  • 19
  • 43
0

In my case, I had to add the VerticalOptions = FillAndExpand to the parent StackLayout as well as set the grandparent Frame to Padding = 0

Philip
  • 638
  • 1
  • 8
  • 22