I’m writing a Windows Phone app in C#. I have a setting OrientationLock that is supposed to lock the screen in portrait orientation. Unfortunately, I can’t for the life of me get it to work. The setting saves and everything, I just can’t figure out how to change the supported orientations in C#. Here’s the code I’m trying to use:
public MainPage()
{
InitializeComponent();
if (AppSettings.Default.OrientationLock)
{
this.SupportedOrientations = SupportedPageOrientation.Portrait;
}
else
{
this.SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
}
}
Thanks.
Eventually you have to move the code to the overridden
OnNavigatedTomethod (in page class) to update the supported orientations if coming back from the settings page… The constructor is only called once (if page was not tombstoned).