2011-05-13 42 views
5

是否可以在Windows Phone 7中手動鎖定手機方向? 因爲我正在使用加速計來處理按鈕的固定UI旋轉。WP7(Windows phone 7)在XAML或C中鎖定手機方向#

我已經試過了:

在XAML

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

而且在後面的代碼:

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

但仍UI之間景觀左移風景權 ...

謝謝。

回答

5

沒有辦法阻止LandscapeLeft和LandScapeRight之間的轉換。這是設計。

作爲解決方法,您可以在OnOrientationChanged中手動旋轉/轉換您的UIElements,以便用戶看不到差異。
我已經使用這種技術來保持「背景」圖像不管方向如何旋轉,但是隨後有一個單獨的控件,它看起來像一個彈出窗口,但對圖像頂部的方向更改做出響應。

+0

在這裏看到示例代碼http://forums.create.msdn.com/forums/t/70673.aspx – 2011-10-09 22:42:15

0

InitializeComponent();之後的MainPage()構造函數中添加此this.SupportedOrientations = SupportedPageOrientation.Portrait;以在縱向模式下鎖定方向。這對我來說可以。

2

嗨,我通過覆蓋OnOrientationChanged方法發現了一個解決方案。這個對我有用。這不會影響系統托盤和應用程序菜單,但頁面保持選定的方向。

protected override void OnOrientationChanged(OrientationChangedEventArgs e) 
{ 
    if (e.Orientation == PageOrientation.LandscapeLeft) 
     base.OnOrientationChanged(e); 
} 
相關問題