Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to populate a Grid programatically in Silverlight?

I have a Grid I am trying to create and populate programatically in Silverlight. However, all of the items just default to spot "0, 0" in the grid despite my efforts. This is what I have:

Grid holdingGrid = new Grid();
int row = 0;

for (int i = 0; i < 10; i++) {
   Expander expander = new Expander();
   holdingGrid.Children.Add(expander);
   Grid.SetRow(expander, row);
   Grid.SetColumn(expander, 0);
   row++;
}

But this still causes all of the items to pile up in the first row and the first column. What am I doing wrong?

like image 570
TheEnigmaMachine Avatar asked Jun 29 '11 20:06

TheEnigmaMachine


1 Answers

Grid holdingGrid = new Grid();
int row = 0;

for (int i = 0; i < 10; i++) {
   Expander expander = new Expander();
   holdingGrid.RowDefinitions.Add(new RowDefinition());
   holdingGrid.Children.Add(expander);
   Grid.SetRow(expander, row);
   Grid.SetColumn(expander, 0);
   row++;
}
like image 90
Vlad Bezden Avatar answered Sep 19 '22 19:09

Vlad Bezden