popupmauimaui-community-toolkit

.Net MAUI Community Toolkit Popup margin


I am trying to achieve the same result from a popup window as in xamarin.forms. For the main popup layout:

Grid gButtons = new Grid()
{
    VerticalOptions = LayoutOptions.Fill,
    HorizontalOptions = LayoutOptions.Fill,
    BackgroundColor = backgroundColor,
    Margin = new Thickness(55, 0, 55, 0),
    ColumnDefinitions = new ColumnDefinitionCollection()
    {
        new ColumnDefinition(){ Width = new GridLength(1, GridUnitType.Star)},
    },
    RowDefinitions = new RowDefinitionCollection()
    {
        new RowDefinition(){ Height = new GridLength(0, GridUnitType.Auto)},
        new RowDefinition(){ Height = new GridLength(0, GridUnitType.Auto)},
    },
};
***
Content = gButtons;

Margin has no effect on window. I can't set hardcoded sizes on popup, because it's bad practice (IMHO). How do I make the margins work?

CommunityToolkit.Maui ver 9.0.2

Platform: Android

.Net ver 8.0


Solution

  • You may try wrapping the Grid with a StackLayout,

    StackLayout stacklayout = new StackLayout();
    Grid gButtons = new Grid()
    ...
    stacklayout.Children.Add(gButtons);
    Content = stacklayout;
    

    Then the margin should work for the Grid.

    You may also try setting the WidthRequest or HeightRequest for the StackLayout to fit the size.