我有两个视图和两个内容页面,在其中一个页面中,我将它们垂直排列,这是在设备处于纵向模式时显示的,就像这样
<StackLayout>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<views:ScoresView Grid.Row="0"/>
<views:CategoriesView Grid.Row="1"/>
</Grid>
</StackLayout>
而其他内容页面为横向模式
<StackLayout>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<views:ScoresView Grid.Column="0"/>
<views:CategoriesView Grid.Column="1"/>
</Grid>
</StackLayout>
这是我在轮换时打电话给另一个的方式
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (width > height)
{
//device is landscape
App.Current.MainPage = new CategoriesLands();
}
else
{
//device is portrait (or square)
}
}
...反之亦然
您可以更改StackLayout StackOrientation
属性以实现效果。
<StackLayout x:Name="outerStack">
<views:ScoresView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
<views:CategoriesView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</StackLayout>
在后面的代码中:
private double width;
private double height;
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (width != this.width || height != this.height)
{
this.width = width;
this.height = height;
if (width > height)
{
outerStack.Orientation = StackOrientation.Horizontal;
}
else
{
outerStack.Orientation = StackOrientation.Vertical;
}
}
}
越多,你可以参考这个。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句