Lock screen orientation .net MAUI

Mielesplayz 291 Reputation points
2022-09-01T09:12:38.8+00:00

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.

Developer technologies | .NET | .NET MAUI
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2022-09-02T07:54:36.39+00:00

    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.

    7 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Horton 0 Reputation points
    2023-10-16T08:16:46.1933333+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.