Lock screen orientation .net MAUI

Mielesplayz 281 Reputation points

Is there a way for you to lock your screen orientation in your .net MAUI app?
I have been searching for a while, but I can't figure out how to do it.

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,845 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,071 Reputation points Microsoft Vendor

    Hello @Mielesplayz ,

    If you want to lock the screen orientation in your app, you can set it individually on each platform.

    On Android:
    You could open MainActivity.cs under Platforms/Android, then change the the orientation attribute.

    [Activity(... ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Landscape)] //This is what controls orientation, you could force the application orientation to be Landscape or Portrait   

    On iOS:
    You could double-click to open info.plist file under Platforms/iOS, then find Device Orientation option and set the screen orientation according to your needs.

    For more details, you can see Device Orientation - Xamarin | Microsoft Learn (These settings apply to Xamarin and MAUI, even though the documentation is about Xamarin)

    Best Regards,
    Wenyan Zhang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    6 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Horton 0 Reputation points
    0 comments No comments