简体   繁体   English

WP7(Windows Phone 7)在XAML或C#中锁定手机方向

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

Is it possible to manualy lock the phone orientation in Windows phone 7 ? 是否有可能在Windows Phone 7中手动锁定手机方向? Because I'm using the accelerometer to handle buttons' rotation with a fixed UI. 因为我正在使用加速度计来处理按钮的固定UI旋转。

I've tried that : 我试过了:

In the XAML 在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 ... 但UI仍然在横向左侧景观之间转换...

Thanks. 谢谢。

There is no way to prevent the shifting between LandscapeLeft and LandScapeRight. 没有办法阻止LandscapeLeft和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. 作为解决方法,您可以在OnOrientationChanged中手动旋转/转换UIElements,以便用户看不到差异。
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. 我已经使用这种技术来保持“背景”图像看起来不管方向旋转,然后有一个单独的控件,它看起来像一个弹出窗口,但它确实响应方向更改显示在图像的顶部。

Hi I found a solution by overriding OnOrientationChanged method. 您好我通过重写OnOrientationChanged方法找到了解决方案。 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);
}

add this this.SupportedOrientations = SupportedPageOrientation.Portrait; 添加此this.SupportedOrientations = SupportedPageOrientation.Portrait; after InitializeComponent(); InitializeComponent(); in MainPage() constructor to lock the orientation in Portrait mode. MainPage()构造函数中以纵向模式锁定方向。 It works fine for me. 这对我来说可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM