我正在用 C# 编写一个 Windows Phone 应用程序。我有一个设置 OrientationLock 应该以纵向锁定屏幕。不幸的是,我终生无法让它发挥作用。设置保存一切,我只是不知道如何更改 C# 中支持的方向。这是我尝试使用的代码:
public MainPage()
{
InitializeComponent();
if (AppSettings.Default.OrientationLock)
{
this.SupportedOrientations = SupportedPageOrientation.Portrait;
}
else
{
this.SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
}
}
谢谢。
请您参考如下方法:
最终,如果从设置页面返回,您必须将代码移动到重写的 OnNavigatedTo 方法(在页面类中)以更新支持的方向...构造函数仅调用一次(如果页面没有墓碑)。
