Grid not expanding to fill screen
Asked Answered
B

2

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.

Boldface answered 22/7, 2015 at 13:25 Comment(3)
Try adding VerticalOptions = LayoutOptions.FillAndExpandto the parent StackLayoutDaveen
HorizontalOptions = LayoutOptions.FillAndExpand worked, thanks!Boldface
Cool glad it worked, I posted it as an answer as wellDaveen
D
14

Try adding VerticalOptions = LayoutOptions.FillAndExpand to the parent StackLayout

Daveen answered 22/7, 2015 at 14:34 Comment(0)
D
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

Dunbarton answered 2/5, 2020 at 23:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.