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?
Asked
Active
Viewed 1,193 times
1
-
1`userControl.Content = grid;` probably – ASh Jul 15 '16 at 09:26
-
yeah it worked but the missing the user control resources of the passed grid in the received User control. – aggy Jul 15 '16 at 09:39
-
Consider make your answer into an answer so it can be accepted as the answer. – Relequestual Jul 15 '16 at 09:51
-
1@govardhan, include all relevant information in the question. it didn't say anything about resources – ASh Jul 15 '16 at 10:38
1 Answers
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