简体   繁体   中英

Changing Orientation on Windows Phone 8

I have a peculiar problem. When I set SupportedOrientations to SupportedPageOrientation.Landscape it automatically changes the orientation to LandscapeLeft, but when I try to change it to SupportedPageOrientation.Portrait it stays in LandscapeLeft.

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);
}

Thanks in advance.

Ok, fixed:

case OrientationLock.VerticalLock:
                this.Dispatcher.BeginInvoke((Action)(()=>{
                this.SupportedOrientations = SupportedPageOrientation.Portrait;}));
                break;

For some reason it isn't necessary for the other two cases. If someone has an explanation I am happy to hear it.

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