我有一个空的
在重写的方法中,我可以获得网格的实际大小:
ContentPage
,里面包含一个Grid
: <Grid
x:Name="YellowGrid"
BackgroundColor="Yellow">
<Label
Text="It's a Yellow Grid"
VerticalOptions="Center"
HorizontalOptions="Center"
/>
</Grid>
在重写的方法中,我可以获得网格的实际大小:
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
// YellowGrid.Width equals to the width of the screen
}
没关系。但是如果我将网格属性IsVisible=false
设置为true,那么YellowGrid
的Width
将等于-1
(这也是合理的)。但是如果它被隐藏了,是否可以获取所需网格的大小呢?
更新
我尝试了下面的方法:
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
var size = YellowGrid.Measure(width, height, MeasureFlags.None);
}
但是Measure
为YellowGrid
返回的是标签Label
所需的大小,而不是整个网格将放置的大小。