How to disable auto rotate for specific control in .NET MAUI

LastPAS Admin 1 Reputation point
2022-11-19T18:46:00.757+00:00

I'm trying to build an application in which an image control has auto rotate disabled, but the rest of the app rotates when the device orientation changes. I'm primarily developing this for use on an iPad, but want the flexibility to expand to Android in the future (hence MAUI).

From what I've found so far, I am going to have to invoke platform-specific code for this to work. This post comes pretty close, but again I'm looking to disable auto rotate on a single image control: https://learn.microsoft.com/en-us/answers/questions/878990/how-to-change-screen-orientation-in-maui.html

I'm brand new to .NET MAUI and app development in general, so any detailed responses and/or solutions would be much appreciated.

Developer technologies .NET .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2022-11-21T08:54:38.987+00:00

    Hello @LastPAS Admin ,

    Disabling or enabling rotation are at the application level, your app can support auto rotation and you can set a certain page not to rotate (the page only supports one device orientation as the thread you mentioned). However, you cannot make individual image controls disable rotation.

    You could choose different layout after the orientation changed, refer to Device Orientation - Xamarin | Microsoft Learn
    (Note: The doc is about Xamarin, it also applies to MAUI, Xamarin.Essentional is a part of MAUI currently)

    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.

    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.