简体   繁体   English

WPF网格制作列和行的快速方法

[英]WPF Grid Quick Way to Make Columns and Rows

Let's say I need to make a with 30 columns and 30 rows. 假设我需要制作一个30列30行的。 Do I have to do <ColumnDefinition></ColumnDefinition> and <RowDefinition></RowDefinition> for 30 times? 我必须做30次<ColumnDefinition></ColumnDefinition><RowDefinition></RowDefinition>吗? Is there any easier/faster method? 有没有简单/快速的方法?

Do I have to do <ColumnDefinition></ColumnDefinition> and <RowDefinition></RowDefinition> for 30 times? 我必须做30次<ColumnDefinition></ColumnDefinition><RowDefinition></RowDefinition>吗? Is there any easier/faster method? 有没有简单/快速的方法?

Create them programmatically using a plain old for loop: 使用普通的for循环以编程方式创建它们:

public MainWindow()
{
    InitializeComponent();
    const int n = 30;
    for (int i = 0; i < n; ++i)
    {
        grid.ColumnDefinitions.Add(new ColumnDefinition());
        grid.RowDefinitions.Add(new RowDefinition());
    }
}

XAML: XAML:

<Grid x:Name="grid" />

It can't be easier. 再简单不过了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM