1

I have a WPF User Control which contains nothing in it, and I'm passing a grid control to it, how do I add that grid control to the empty User Control?

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
aggy
  • 163
  • 1
  • 2
  • 14

1 Answers1

1

Here is the sample code on how to achieve to add a grid programmatically. This grid contains 3 equal rows and 3 equal columns. Change it to something you want to have.

Grid grid1 = new Grid{Width = 300, Height = 400};
grid1.RowDefinitions.Add(new RowDefinition());
grid1.RowDefinitions.Add(new RowDefinition());
grid1.RowDefinitions.Add(new RowDefinition());
grid1.ColumnDefinitions.Add(new ColumnDefinition());
grid1.ColumnDefinitions.Add(new ColumnDefinition());
grid1.ColumnDefinitions.Add(new ColumnDefinition());
UserControl1.Content = grid1;
ViVi
  • 4,339
  • 8
  • 29
  • 52