4

デバイスが縦向き(縦向き)か横向き(横向き)かをどのように判断できますか?

これを単純化するAPIはありますか、それとも加速度計を使用して「手動で」決定する必要がありますか?

4

3 に答える 3

4

私自身、Windows 7の電話を見たばかりです(vs2010 Express Phone Editionまで)。

この背後にあるコードにあるようです

 public MainPage()
        {
            InitializeComponent();
            // seems to set the supported orientations that your program will support.
            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
        }

次に、実際のフォームは

  private void PhoneApplicationPage_OrientationChanging(object sender, OrientationChangedEventArgs e)
        {
            var test = e.Orientation;

        }

したがって、向きが変わると、e.Orientationはそれがどの向きかを教えてくれます。たとえばLandscapeRightのように。

于 2010-03-18T21:39:11.710 に答える
2

また、これをイベント経由でのみ追跡する必要はありません。PhoneApplicationPageインスタンスから直接要求できます。

private void Button_Click(object sender, RoutedEventArgs e)
{
    MyCurrentOrientation.Text = this.Orientation.ToString();
}
于 2010-04-02T23:12:37.933 に答える
0

また、これを介して質問することもできます。アプリケーションの開始時のオリエンテーションにより、オリエンテーションが何であるかがわかります。開始後、OrientationChangedイベントを使用できます。

あなたのメインで:

OrientationChanged += new EventHandler<OrientationChangedEventArgs>(MainPage_OrientationChanged);

void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e)

{

   Console.WriteLine(e.Orientation.ToString());

}
于 2010-03-19T17:16:25.810 に答える