Answer the question
In order to leave comments, you need to log in
Create Grid programmatically in wpf?
You need to create a Grid with a size of 12 * 3 - that is, 12 in length and 3 in height,
and assign a button to each cell
. Did this:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
RowDefinitionCollection rd = MainGrid.RowDefinitions;
ColumnDefinitionCollection cd = MainGrid.ColumnDefinitions;
for (int i = 0; i < 3; i++)
{
rd.Add(new RowDefinition());
for (int j = 0; j < 12; j++)
{
cd.Add(new ColumnDefinition());
}
Button b = new Button();
b.Name = "Button"+i;
}
Answer the question
In order to leave comments, you need to log in
RowDefinitionCollection rd = MainGrid.RowDefinitions;
ColumnDefinitionCollection cd = MainGrid.ColumnDefinitions;
for (int i = 0; i < 3; i++)
{
rd.Add(new RowDefinition());
for (int j = 0; j < 12; j++)
{
cd.Add(new ColumnDefinition());
Button b = new Button();
b.Name = "Button"+i;
MainGrid.Children.Add(b);
Grid.SetColumn(b, j);
Grid.SetRow(b, i);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question