How do you set screen orientation programatically?

  • Thread starter Thread starter WPCentral Question
  • Start date Start date
W

WPCentral Question

Hi all,

I am new to wp8 developing and would like to set my app to only work in landscape mode is this possible?
 
I have the code but don't have my Surface with me. I'll post later if somebody else hasn't done so.


Sent from my iPhone using Tapatalk
 
Here's the stripped down version of one of my code...

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SolidColorBrush = System.Windows.Media.SolidColorBrush;

namespace <yourapp namespace>
{
    public partial class SettingsPage : PhoneApplicationPage
    {
        private static AppSettings settings;

        public SettingsPage()
        {
            InitializeComponent();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            settings = new AppSettings();

            bool locked = settings.OrientationLockSetting;
            bool useAccent = settings.UseThemeColorSetting;

            SetOrientation(locked);
            base.OnNavigatedTo(e);
        }
        private void SetOrientation(bool locked)
        {
            this.SupportedOrientations = locked ? SupportedPageOrientation.Portrait : SupportedPageOrientation.PortraitOrLandscape;
        }
    }
}

You can replace this

this.SupportedOrientations = locked ? SupportedPageOrientation.Portrait : SupportedPageOrientation.PortraitOrLandscape;

with this

this.SupportedOrientations = SupportedPageOrientation.Portrait;
 

Members online

Forum statistics

Threads
335,157
Messages
2,258,151
Members
428,735
Latest member
arynnadii