Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

c# - How to set Supported orientations property in Windows Phone 8.1

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...