简体   繁体   中英

Changing Supported Orientations

I'm writing a Windows Phone app in C#. I have a setting OrientationLock that is supposed to lock the screen in portrait orientation. Unfortunately, I can't for the life of me get it to work. The setting saves and everything, I just can't figure out how to change the supported orientations in C#. Here's the code I'm trying to use:

public MainPage()
{
    InitializeComponent();

    if (AppSettings.Default.OrientationLock)
    {
        this.SupportedOrientations = SupportedPageOrientation.Portrait;
    }
    else
    {
        this.SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
    }
}

Thanks.

最终,如果从设置页面返回,则必须将代码移动到重写的OnNavigatedTo方法(在页面类中)以更新支持的方向...构造函数仅被调用一次(如果页面未被逻辑删除)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM