.Net MAUI 社区工具包弹出边距

问题描述 投票:0回答:1

我试图从弹出窗口中获得与 xamarin.forms 相同的结果。对于主要弹出布局:

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 对窗口没有影响。我无法在弹出窗口上设置硬编码大小,因为这是不好的做法(恕我直言)。如何使边距发挥作用?

CommunityToolkit.Maui 版本 9.0.2

平台:安卓

.Net 版本 8.0

popup maui maui-community-toolkit
1个回答
0
投票

您可以尝试用

Grid
,
 包裹 
StackLayout

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

那么边距应该适用于

Grid

您也可以尝试设置

WidthRequest
HeightRequest
StackLayout
以适合尺寸。

© www.soinside.com 2019 - 2024. All rights reserved.