我试着得到网格的高度和宽度:
int numberOfColumnsInGameView = (int)(gameView.Width / objectSize);
int numberOfRowsInGameView = (int)(gameView.Height / objectSize -0.5);其中gameView是网格。当我尝试赋值给变量时,我有var = NaN
发布于 2014-05-24 17:38:11
我建议您使用Grid.ActualHeight和Grid.ActualWidth属性。只有在需要设置新值时,才应该使用Height和Width。
发布于 2014-05-26 10:00:55
最保守的方法可能是这样做:
private double HeightOf(FrameworkElement element)
{
if (double.IsNaN(element.Height))
return element.ActualHeight;
if (double.IsNaN(element.ActualHeight))
return element.Height;
return Math.Max(element.Height, element.ActualHeight);
}通过这种方式,您可以处理以下情况:
ActualHeight) (→)Height)。发布于 2014-05-26 15:51:53
我明白了。
this.Loaded += MainPage_Loaded;
.........
private void GeneranteLevel(int level)
{
int numberOfColumnsInGameView = (int)(gameView.ActualWidth / objectSize);
int numberOfRowsInGameView = (int)(gameView.ActualHeight / objectSize -0.5);
........https://stackoverflow.com/questions/23847527
复制相似问题