4

I've created a Xamarin.Forms app that I want to only run in landscape orientation. This is easy enough for iOS, where setting the device orientation in Info.plist does the trick.

But for UWP, this does not appear to work. In Package.appxmanifest I've set the Supported rotations to Landscape only:

enter image description here

But I'm still able to rotate into portrait mode.

Is this a bug, and is there a workaround?

jbyrd
  • 5,287
  • 7
  • 52
  • 86

1 Answers1

2

The orientation lock is only respected when the system is in the Tablet mode or in the Kiosk mode, because when the app is windowed, it is not possible to limit its orientation (user can change it freely).

Also note that maximized window <> Tablet mode, so even if the app view is maximized, it will still rotate freely.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • I am in tablet mode - I've tested on both a 2-in-1 that turns into a tablet, and also an actual standalone tablet (Surface 3), but it's still rotating into portrait mode. – jbyrd Jan 18 '18 at 19:10
  • But have you tested in the actual Tablet mode? You can turn it on in the Action center – Martin Zikmund Jan 18 '18 at 19:11
  • 1
    Interesting! So I have a Lenova Yoga that automatically changes to tablet mode when you flip the screen back. To confirm, in the tablet mode settings, I selected "Always ask me before switching" - and now when I flip the screen back, sure enough it asks "Do you want to switch to tablet mode?" But when I'm in tablet mode and have the app open, when I rotate the device to portrait mode, it asks me "Do you want to exit out of tablet mode?" If I say no, then it remains in landscape just as it should. I guess what I didn't realize before is that it was exiting out of tablet mode! – jbyrd Jan 18 '18 at 19:38
  • Interesting! I didn't know it can drop out of the mode automatically when a non-portrait app is currently open :-). – Martin Zikmund Jan 18 '18 at 19:41
  • So is there a workaround (maybe in code) to get the app to stay in landscape mode even not in tablet mode? – jbyrd Jan 18 '18 at 20:23
  • 1
    Unfortunately not, since when it is just a window, it can resize as it pleases. You could observe the `SizeChanged` event and then use `TryResizeView` to force the app into your preferred aspect ratio, but that is the most you can get... – Martin Zikmund Jan 18 '18 at 20:27