看起来更改 a 的属性Orientation
由于某种原因不起作用。所以这里有一个替代方案。FlipView
ItemsPanel
您将需要复制您的FlipView
. 一个将实现 a Vertical
VirtualizingStackPanel
,另一个将实现 a Horizontal
VirtualizingStackPanel
。
在页面的Resources
.
<Page.Resources>
<ItemsPanelTemplate x:Key="HorizontalItemsPanel">
<VirtualizingStackPanel AreScrollSnapPointsRegular="True" Orientation="Horizontal" />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="VerticalItemsPanel">
<VirtualizingStackPanel AreScrollSnapPointsRegular="True" Orientation="Vertical" />
</ItemsPanelTemplate>
</Page.Resources>
然后,您将要使用SimpleOrientationSensor
来监控手机的方向变化。
private SimpleOrientationSensor _orientationSensor = SimpleOrientationSensor.GetDefault();
在你订阅了它的OrientationChanged
事件之后,
_orientationSensor.OrientationChanged += OrientationSensor_OrientationChanged;
在其回调中,只需FlipView
相应地隐藏和显示 s 。
private async void OrientationSensor_OrientationChanged(SimpleOrientationSensor sender, SimpleOrientationSensorOrientationChangedEventArgs args)
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
switch (args.Orientation)
{
case SimpleOrientation.NotRotated:
case SimpleOrientation.Rotated180DegreesCounterclockwise:
this.HorizontalFlipView.Visibility = Visibility.Visible;
this.VerticalFlipView.Visibility = Visibility.Collapsed;
break;
case SimpleOrientation.Rotated90DegreesCounterclockwise:
case SimpleOrientation.Rotated270DegreesCounterclockwise:
this.HorizontalFlipView.Visibility = Visibility.Collapsed;
this.VerticalFlipView.Visibility = Visibility.Visible;
break;
}
});
}