C# 在Windows Phone 8上更改方向
我有一个特殊的问题。当我将SupportedOrientations设置为SupportedPageOrientation.横向时,它会自动将方向更改为LandscapeLeft,但当我尝试将其更改为SupportedPageOrientation.Grait时,它会保留在LandscapeLeft中C# 在Windows Phone 8上更改方向,c#,windows-phone-8,orientation,C#,Windows Phone 8,Orientation,我有一个特殊的问题。当我将SupportedOrientations设置为SupportedPageOrientation.横向时,它会自动将方向更改为LandscapeLeft,但当我尝试将其更改为SupportedPageOrientation.Grait时,它会保留在LandscapeLeft中 protected override async void OnNavigatedTo(NavigationEventArgs e) { switch (Settings.
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
switch (Settings.OrientationLock)
{
case OrientationLock.Rotate:
this.SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
break;
case OrientationLock.HorizontalLock:
this.SupportedOrientations = SupportedPageOrientation.Landscape;
break;
case OrientationLock.VerticalLock:
this.SupportedOrientations = SupportedPageOrientation.Portrait;
break;
}
...
base.OnNavigatedTo(e);
}
提前感谢。好的,修复了:
case OrientationLock.VerticalLock:
this.Dispatcher.BeginInvoke((Action)(()=>{
this.SupportedOrientations = SupportedPageOrientation.Portrait;}));
break;
出于某种原因,其他两种情况不需要。如果有人有解释,我很高兴听到。无法复制。您是如何测试的?我正在测试诺基亚Lumia 620开发套件。Settings是我创建的一个静态类,用于存储应用程序中使用的设置。方向锁是我在那里定义的枚举的一个实例。那部分很好用。SupportedOrientations设置正确,但这个。方向不变。这真的很奇怪。是的,我知道。这就是为什么我没有将自己的答案标记为已接受答案的原因。我想要解释一下。我真的不喜欢幻想书之外的魔法和巫毒。这是我唯一一部使用WindowsPhone8OS的手机。Emulator不是此应用程序的选项,因为我使用ARM处理器库。简言之,我太懒了,无法启动另一个项目来测试它。