【发布时间】:2017-10-23 10:14:07
【问题描述】:
我有一个空的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,则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 所需的大小,而不是网格将放置的整个大小。
【问题讨论】:
标签: c# xamarin.forms