Search code examples
windows-store-appsscreen-orientation

Changing Supported Page Orientation programmatically for Windows 8.1 Phone


My application supports both Portrait and Landscape orientations and automatically adapts UI to screen size. However I want to provide an option to lock the screen at current orientation.

If I just stop processing SizeChanged event, it doesn't help, since system still rotates the UI page, so it appears squeezed and truncated.

According to MSDN there is a way to set up supported orientations programmatically in Xna and Silverlight or Windows API (which is disallowed to use by Windows Store App). Is there a way to do that for an Universal app (Windows 8.1 or Windows 10)?


Solution

  • You can control this by setting the DisplayInformation.AutoRotationPreferences.

    e.g.

    DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
    

    set it to .None if you want to support both.