title: How to get orientation of the phone with SupportedOrientations="Portrait"
body: <p>I write a simple game with using MonoGame library. As far as I know MonoGame (unlike XNA) doesn't automatically support changing orientation of the phone and it is necessary to use RenderTarget2D and then draw it with a proper orientation. For this purpose I need to detect current orientation of the phone.</p>
  
  <p>In order to get OrientationChanged event, I have to allow GamePage.xaml to use different orientations:</p>
  
  <pre><code>SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
  </code></pre>
  
  <p>The problem is that in this case my GamePage starts changing orientations automatically and in landscape position sprites are stretched horizontally. It seems that in the landscape position phone thinks that it has the same number of pixels along horizontal side as in the portrait orientation (480 pixels). </p>
  
  <p><img src="https://i.stack.imgur.com/wdEuc.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/r5eEE.png" alt="enter image description here"></p>
  
  <p>This effect happens without any manual rotation. The code of drawing is:</p>
  
  <pre><code>protected override void Draw(GameTime gameTime)
  {
      GraphicsDevice.Clear(Color.CornflowerBlue);
  
      spriteBatch.Begin();
      spriteBatch.Draw(t, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
      spriteBatch.End();
  
      base.Draw(gameTime);
  }
  </code></pre>
  
  <p>One of the solutions is to forbid different orientations in GamePage.xaml:</p>
  
  <pre><code>SupportedOrientations="Portrait" Orientation="Portrait"
  </code></pre>
  
  <p>but in this case I can't get the OrientationChanged event nowhere (GamePage.OrientationChanged or Game.Window.OrientationChanged). I put following code in the constructor of Game class, but it didn't help</p>
  
  <pre><code>graphics.SupportedOrientations = DisplayOrientation.Portrait |
                                   DisplayOrientation.PortraitDown |
                                   DisplayOrientation.LandscapeLeft |
                                   DisplayOrientation.LandscapeRight;
  
  graphics.ApplyChanges();
  this.Window.OrientationChanged += OrientationChanged;
  </code></pre>
  
  <p>Please advise me how to get OrientationChanged event and at the same time don't allow GamePage to change its coordinate axes in landscape mode.</p>