Reputation: 8126
A want to create an Metro Style Windows 8 application that doesn't rotate a root Grid
with all content in Portrait
mode. I want to handle orientation in Code
and by Visual States
, but now when I rotate device, all content is automatically rotates and fill new width and height.
How can I disable this rotation behavior, i.e. disable Portrait
orientation, but is still be able to get events about orientation changes?
Also, Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences
doesn't seems to work
Upvotes: 5
Views: 2996
Reputation: 281
Sorry I missed your primary question. I don't think you can change the "rotation" of the root element after the portrait mode event. Because its actually not rotated relative to the screen, but screen size is changed.
However, I suppose you still want the user to look at your app in landscape mode after the portrait mode event. You can counter the perceived rotation. You can put you business logic in another user control with no predefined size. Put this user control in the root page. When you received the portrait mode event, you assign page ActualWidth to user control height, page ActualHeight to user control Width, the give user control a render transform of 90 degrees and render transform center x=height*0.707/width, y=0.5, then user control should just align to the landscape mode position.
Upvotes: 0
Reputation: 281
Double click the "Package.appxmanifest" file in your metro app project, you should see configurations of your app. In the "Application UI" page, you can find "Supported rotations" in the middle. You can check the mode you supported, and leave the "Portrait" mode unchecked. Then you app will not receive any "portrait" mode events anymore.
If you write your own appx manifiest, you can add following block under section, like this
<InitialRotationPreference>
<Rotation Preference="landscape" />
<Rotation Preference="portraitFlipped" />
<Rotation Preference="landscapeFlipped" />
</InitialRotationPreference>
Upvotes: 3
Reputation: 29073
When Windows says you're in portrait mode, add a rotatetransform to your root element that counters that and keeps things rendered portrait
Upvotes: 0