设置网格的相对高度 children

Setting relative height for Grid children

我将 2 children 添加到这样的网格中:

    private void pInitStackLayout()
    {
        grid1 = new Grid()
        {
        };

        grid2 = new Grid()
        {
        };

        biggrid = new Grid()
        {
            BackgroundColor = Color.Transparent,
            Margin = new Thickness(0),
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.StartAndExpand,
            Orientation = StackOrientation.Vertical,
        };
        biggrid.Children.Add(grid1,0,0);
        biggrid.Children.Add(grid2,0,1);

        this.Content = biggrid;
    }

ContentPage(导航页面)的内容是大网格。

我想使 grid1 占据可用高度的 80%,grid2 占据 20%(或其余)。

我怎样才能做到这一点?

其实很简单,设置biggrid的RowDefinitions就可以了。

// RowDefinitions isolated

RowDefinitions = new RowDefinitionCollection
{
    new RowDefinition { Height = new GridLength(8, GridUnitType.Star) },
    new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }
}

// RowDefinitions isolated

// Actual code
private void pInitStackLayout()
{
    grid1 = new Grid()
    {
    };

    grid2 = new Grid()
    {
    };

    biggrid = new Grid()
    {
        RowDefinitions = new RowDefinitionCollection
        {
            new RowDefinition { Height = new GridLength(8, GridUnitType.Star) },
            new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }
        },

        BackgroundColor = Color.Transparent,
        Margin = new Thickness(0),
        HorizontalOptions = LayoutOptions.FillAndExpand,
        VerticalOptions = LayoutOptions.StartAndExpand,
        Orientation = StackOrientation.Vertical,
    };
    biggrid.Children.Add(grid1,0,0);
    biggrid.Children.Add(grid2,0,1);

    this.Content = biggrid;
}