It's been 2 hours of struggle against SL grid on WP7. I build my grid using the following code:
public void initUIBoard() {
int x, y;
Button b;
for (x = 0; x < mine.cRows; x++) {
RowDefinition rd = new RowDefinition();
rd.Height = new GridLength(20);
uiBoard.RowDefinitions.Add(rd);
}
for (y = 0; y < mine.cColumns; y++) {
ColumnDefinition cd = new ColumnDefinition();
cd.Width = new GridLength(20);
uiBoard.ColumnDefinitions.Add(cd);
}
for (x = 0; x < mine.cRows; x++)
for (y = 0; y < mine.cColumns; y++)
{
b = new Button();
b.Click += new RoutedEventHandler(this.caseClick);
b.Tag = mine.gameBoard[x][y];
Grid.SetRow(b, x);
Grid.SetColumn(b, y);
uiBoard.Children.Add(b);
}
}
The thing is, my grid is shown empty, am I doing something wrong with these Rows/Columns definition or something ?
Thanks in advance
After some experimentation, it looks like
GridLength
isn't calculating heights in pixels correctly.Because the grid cell created isn't large enough the control is not shown.
Try increasing the sizes used for grid length. I did the following and got some output.
Alternatively, consider setting the Heights and Widths to by dynamically sized. e.g.:
If you can investigate this height issue some more and also find it to be a height issue bug then please submit it to Microsoft.
Your code seems to work fine (I tried on Silverlight non-Winphone, but should be the same).
My guess is that the cause is somewhere else, for ex. another element covering the uiBoard grid, or the buttons being transparent with no background color/border.