Reputation: 61
I wanted to Create a Grid Dynamically into Page. I am using this Code:
Grid grd = new Grid();
for (int i = 0; i <MAX_X; i++)
{
grd.RowDefinitions.Add(new RowDefinition());
}
for (int i = 0; i <MAX_Y; i++)
{
grd.ColumnDefinitions.Add(new ColumnDefinition());
}
for (int x = 0; x <= MAX_X; x++)
{
for (int y = 0; y <= MAX_Y; y++)
{
TextBlock t = new TextBlock();
t.SetValue(Grid.RowProperty, x);
t.SetValue(Grid.ColumnProperty, y);
t.text = "Hello";
grd.Children.Add(t);
}
}
It is created but not displaying anything. When i do Debug, Its Working fine but its not displaying in my Page. am i missing Something ?
Upvotes: 2
Views: 281
Reputation: 2621
Your Grid doesnt have any parent that resides into Page. You needed to add Your Grid to the Page. It is created but not been added to Page so its not Displaying anything.
Try this:
ContentPanel.Children.Add(grd);
Upvotes: 1