[英]Windows Phone get height and width of grid
I try to get get height and width of grid: 我尝试获取网格的高度和宽度:
int numberOfColumnsInGameView = (int)(gameView.Width / objectSize);
int numberOfRowsInGameView = (int)(gameView.Height / objectSize -0.5);
Where gameView
is grid. 其中
gameView
是网格。 When I try assign to variable I have that var = NaN
当我尝试分配给变量时,我有var =
NaN
I suggest you to use Grid.ActualHeight
and Grid.ActualWidth
properties. 我建议您使用
Grid.ActualHeight
和Grid.ActualWidth
属性。 You should use Height
and Width
only if you need to set a new value. 仅在需要设置新值时才应使用“
Height
和“ Width
。
The most conservative way is probably to do something like this: 最保守的方法可能是执行以下操作:
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);
}
This way, you cover the following cases: 这样,您可以涵盖以下情况:
ActualHeight
) ActualHeight
) Height
) Height
) Thx I understood. 我明白了。
this.Loaded += MainPage_Loaded;
.........
private void GeneranteLevel(int level)
{
int numberOfColumnsInGameView = (int)(gameView.ActualWidth / objectSize);
int numberOfRowsInGameView = (int)(gameView.ActualHeight / objectSize -0.5);
........
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.