Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I wrote an application for WP 8 some time ago, I'm currently working on updating it for WP 8.1.

My XAML and C#-skills have improved a lot since the initial launch, so I decided to rewrite it from scratch in order to avoid digging through old, noob code (yeah... it isn't pretty).

One thing that I can't seem to get my head around is how to deal with enabling and disabling orientation-changes for the app. I've found a way to make a total enable/disable with the "Package.appmanifest". That's not quite what I'm after however.

I simply wrote this at the top of my app pages in the old version:

<phone:PhoneApplicationPage
SupportedOrientations="PortraitOrLandscape"
etc...
etc...
>

This suited me very well since some pages simply didn't work in both portrait and landscape mode. (I spent more time than I care to remember trying to make it work...) But it won't work in 8.1.

Would some kind soul know of a way to set desired orientation-support per page in Windows Phone 8.1?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
319 views
Welcome To Ask or Share your Answers For Others

1 Answer

You could do this if you wanted just portrait

DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;

Or this if you wanted Portrait and Landscape

DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait | DisplayOrientations.Landscape;

Or if you wanted just Landscape and Landscape Flipped

DisplayInformation.AutoRotationPreferences = DisplayOrientations.LandscapeFlipped | DisplayOrientations.Landscape;

etc. on every page, so you can enable/disable orientations depending on the page and how you intend to use it. You can set it in OnNavigatedTo event handler for example.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    DisplayInformation.AutoRotationPreferences = DisplayOrientations.LandscapeFlipped | DisplayOrientations.Landscape;

    this.navigationHelper.OnNavigatedTo(e);
}

Read more about DisplayInformation.AutoRotationPreferences here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...