Filip
Filip

Reputation: 864

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.

Upvotes: 0

Views: 2173

Answers (1)

Filip
Filip

Reputation: 864

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.

Upvotes: 1

Related Questions