Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP7 (Windows phone 7) Lock phone orientation in XAML or C#

Is it possible to manualy lock the phone orientation in Windows phone 7 ? Because I'm using the accelerometer to handle buttons' rotation with a fixed UI.

I've tried that :

In the XAML

SupportedOrientations="Landscape" Orientation="LandscapeLeft"
OrientationChanged="PhoneApplicationPage_OrientationChanged"

And in the code behind :

private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
    //Orientation locking
    //Do nothing
}

But the UI is still shifting between landscape left and landscape right...

Thanks.

like image 778
Mualig Avatar asked May 13 '11 09:05

Mualig


2 Answers

There is no way to prevent the shifting between LandscapeLeft and LandScapeRight. This is by design.

As a work around, you can manually rotate/transform your UIElements in the OnOrientationChanged so that the user doesn't see a difference.
I've used this technique to keep a "background" image from appearing to rotate regardless of orientation but then having a separate control which appears like a popup but which does respond to orientation changes show on top of the image.

like image 146
Matt Lacey Avatar answered Sep 18 '22 11:09

Matt Lacey


Hi I found a solution by overriding OnOrientationChanged method. It works for me. That do not affect system tray and application menu, but page stay in the selected orientation.

protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
    if (e.Orientation == PageOrientation.LandscapeLeft)
        base.OnOrientationChanged(e);
}
like image 39
jermy7 Avatar answered Sep 17 '22 11:09

jermy7