简体   繁体   中英

WP7 Silverlight grid not showing content

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.

rd.Height = new GridLength(40);

Alternatively, consider setting the Heights and Widths to by dynamically sized. eg:

rd.Height = new GridLength(1, GridUnitType.Auto);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM