Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grid not expanding to fill screen

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.

like image 353
Ilia Stoilov Avatar asked Jul 22 '15 13:07

Ilia Stoilov


1 Answers

Try adding VerticalOptions = LayoutOptions.FillAndExpand to the parent StackLayout

like image 96
pnavk Avatar answered Sep 29 '22 14:09

pnavk