のOrientation
プロパティを変更しても、何らかの理由で機能しないようです。だからここに代替案があります。FlipView
ItemsPanel
を複製する必要がありますFlipView
。1 つは a を実装し、もう 1 つは a を実装しVertical
VirtualizingStackPanel
ます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;
}
});
}