How to limit orientation in metro applications?

In my application, all things are in landscape mode only. I do not want the app to function in portrait mode. How to limit orientation?

Thanks.

+7
source share
3 answers

As explained in this link , setting preferences for restricting orientation of an application only applies to Windows 8 with a supported EQUIPMENT DEVICE. This means that if Windows does not know how the system is oriented using a supported sensor, it will not try to switch to the preferred orientation of the application.

Thus, it all depends on the user equipment.

+4
source

I had this problem, and I wanted to keep my game only in landscape mode. I put this in my OnLaunched handler for App.xaml:

Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences = Windows.Graphics.Display.DisplayOrientations.Landscape; 

However, I noticed that in the simulator, this seemed to ignore it, whereas on the hardware tablet that I tested on it seemed to behave properly. AutoRotationPreferences are bit flags, so you can either combine all the orientations you want to allow.

+4
source

For people who want to answer this question who don’t write the Metro app (where you can set preferred orientations in the manifest or have access to Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences ) ...

There is no real way to NOT allow a change in Orientation, however, if you are only interested in the fact that the Landscape could do something like this:

View Model:

 Microsoft.Win32.SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged); } public bool IsLandscape { get; set; } void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e) { if (SystemParameters.PrimaryScreenWidth > SystemParameters.PrimaryScreenHeight) { IsLandscape = true; } else { IsLandscape = false; } RaisePropertyChanged( "IsLandscape" ); } 

In the main .xaml window:

 <Border > <Border.Style> <Style TargetType="{x:Type Border}"> <Style.Triggers> <DataTrigger Binding="{Binding IsLandscape}" Value="False"> <Setter Property="LayoutTransform"> <Setter.Value> <RotateTransform Angle="90"/> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style> </Border.Style> ///The rest of your controls and UI </Border> 

Thus, we really do not limit Orientation, we just notice when this happens, and rotate our user interface so that it still looks like in portrait mode :) Again, this is mainly for applications that do not support Metro Win 8, and applications that also run on Win 7 tablets.

0
source

All Articles