question

Mielesplayz avatar image
0 Votes"
Mielesplayz asked WenyanZhang-MSFT commented

Lock screen orientation .net MAUI

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.

dotnet-maui
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Wenyan, how can we fix this issue on an app built for Microsoft environment?
Thanks in advance
Michele

0 Votes 0 ·

Hi @WenyanZhang-MSFT , how can we fix this issue on an app built for Microsoft environment?
thanks in advance
Michele

0 Votes 0 ·
WenyanZhang-MSFT avatar image WenyanZhang-MSFT MicheleCrivellari-6094 ·

You could open Package.appxmanifest file under Platforms/Windows, and check the option of Supported rotations. For further support, you can post a new thread.

0 Votes 0 ·

1 Answer

WenyanZhang-MSFT avatar image
2 Votes"
WenyanZhang-MSFT answered Dustin-3796 edited

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 Docs (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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.