Looks like changing the Orientation
property of a FlipView
's ItemsPanel
doesn't work for some reason. So here's an alternative.
You will need to duplicate your FlipView
. One would implement a Vertical
VirtualizingStackPanel
and the other a Horizontal
VirtualizingStackPanel
.
Define them in your page's 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>
Then, you will want to use SimpleOrientationSensor
to monitor the phone's orientation changes.
private SimpleOrientationSensor _orientationSensor = SimpleOrientationSensor.GetDefault();
After you have subscribed to its OrientationChanged
event,
_orientationSensor.OrientationChanged += OrientationSensor_OrientationChanged;
in its callback, simply hide and show the FlipView
s accordingly.
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;
}
});
}