具有不同列数的行的网格

时间:2018-04-19 21:48:46

标签: xamarin.forms

是否可以以编程方式创建一个包含3行和2列的Grid,但最后一行只有1列而不是2?

public class MyGrid : Grid
{
    public void DefineRowsAndColumns()
    {
        // I know you can add RowDefinitions and ColumnDefinitions here, but how to make them uneven?
    }
}

我不想让别人在这里做我的作业......我只是想知道如何让网格有不同列数的行。

1 个答案:

答案 0 :(得分:2)

您可以使用ColumnSpan属性使内容跨越多列

var label = new Label { Text = "Row 1" };
myGrid.Children.Add(label,0,0);
Grid.SetColumnSpan(label,2);

Label将跨越2列,有效地使该行只包含一列