简体   繁体   中英

WPF Grid Quick Way to Make Columns and Rows

Let's say I need to make a with 30 columns and 30 rows. Do I have to do <ColumnDefinition></ColumnDefinition> and <RowDefinition></RowDefinition> for 30 times? Is there any easier/faster method?

Do I have to do <ColumnDefinition></ColumnDefinition> and <RowDefinition></RowDefinition> for 30 times? Is there any easier/faster method?

Create them programmatically using a plain old for loop:

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:

<Grid x:Name="grid" />

It can't be easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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