Larsenal
Larsenal

Reputation: 51196

How to determine orientation of Windows Phone 7?

How can you tell whether the device is oriented vertically (portrait) or horizontally (landscape)?

Is there an API that simplifies this or do you have to make the determination "by hand" using the accelerometer?

Upvotes: 4

Views: 832

Answers (3)

Shawn Oster
Shawn Oster

Reputation: 151

Also you don't have to track this only via the event, you can ask for it directly from the PhoneApplicationPage instance:

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

Upvotes: 2

matthijs Hoekstra
matthijs Hoekstra

Reputation: 397

You can also ask it through this.Orientation when your application starts so you know what the orientation is. Afther the start 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());

}

Upvotes: 0

chobo2
chobo2

Reputation: 85855

I myself just have looked at windows 7 phones(through vs2010 express phone edition).

It seems to have 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 actual form has

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

        }

So when the orientation changes it e.Orientation will tell you what orientation it is. Like for instance LandscapeRight.

Upvotes: 4

Related Questions