How to determine the orientation of Windows Phone 7?

How can you determine if a device is oriented vertically (portrait) or horizontally (landscape)?

Is there an API that simplifies this, or do you need to do a manual definition with an accelerometer?

+4
source share
3 answers

I myself just looked at Windows 7 phones (via the version of the express version vs2010).

It seems that in the code behind this

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

Then the real form has

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

So, when the orientation changes, e.Orientation will tell you which orientation. For example, LandscapeRight.

+4
source

Also, you do not need to track this only through the event, you can request it directly from the PhoneApplicationPage instance:

 private void Button_Click(object sender, RoutedEventArgs e) { MyCurrentOrientation.Text = this.Orientation.ToString(); } 
+2
source

You can also ask a question through this. Orientation, when your application starts, so you know what orientation is. At the beginning, you can use the OrientationChanged event.

In your main:

 OrientationChanged += new EventHandler<OrientationChangedEventArgs>(MainPage_OrientationChanged); void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { Console.WriteLine(e.Orientation.ToString()); } 
0
source

Source: https://habr.com/ru/post/1304510/


All Articles