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

前端 未结 3 918
南笙
南笙 2021-01-19 03:02

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 tr

相关标签:
3条回答
  • 2021-01-19 03:11

    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);
    }
    
    0 讨论(0)
  • 2021-01-19 03:13

    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.

    0 讨论(0)
  • 2021-01-19 03:20

    add this this.SupportedOrientations = SupportedPageOrientation.Portrait; after InitializeComponent(); in MainPage() constructor to lock the orientation in Portrait mode. It works fine for me.

    0 讨论(0)
提交回复
热议问题