所以设置网格rows/columns为默认填充?

So set grid rows/columns to default filling?

当我创建包含行或列的网格时,如果我没有指定 width/height,column/row 将其 height/width 调整为如下内容:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <Button Content="TestBtn"
                Height="50"
                Width="100"/>

    </Grid>

行将其高度设置为 50。

问题:如何在代码中自定义设置 width/height 后 return row/column 到默认行为?像这样:

    public void SetRowHeight(double height, bool setDefault)
    {
        if (setDefault)
        {
            Grid0Row1.DefaultHeightBehaivor = true;
        }
        else
        {
            Grid0Row1.Height = new GridLength(Height);
        }
    }

为此,您需要使用带空参数的 new GridLength(),代码将如下所示:

public void SetRowHeight(double height, bool setDefault)
{
    if (setDefault)
    {
        Grid0Row1.Height = new GridLength();
    }
    else
    {
        Grid0Row1.Height = new GridLength(height);
    }
}