How do you set screen orientation programatically?

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?
 

azcruz

Active member
Jul 29, 2013
3,417
0
36
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
 

azcruz

Active member
Jul 29, 2013
3,417
0
36
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
330,097
Messages
2,252,946
Members
428,728
Latest member
tanvisharmaservice000