MAUI: How to customize style and use specific windows control?

Minh Van 171 Reputation points
2023-10-06T04:31:19.22+00:00

Hi,

I'm new to MAUI and have some requirements to check whether it is possible and how to do it in MAUI:

  1. Some features/controls are only available/shown on Windows platform and hidden for mobiles.
  2. Some features/controls have different layout and behavior on Windows platforms. Is there any way to customize it by introducing new <Style x:Key="MyStyle"> and custom control (I think it should be added into Platforms/Windows/App.xaml) and then can reference it from MAUI.

Thanks.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,075 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,106 Reputation points Microsoft External Staff
    2023-10-09T02:34:41.4933333+00:00

    Hello,

    In MAUI, you could use OnPlatform to implement this requirement.

    Please refer to the following official documentation and code samples:

    // In this example, this BoxView is only visible on the Windows platform.
     <BoxView Color="{OnPlatform Yellow, iOS=Red, Android=Green}"
    WidthRequest="{OnPlatform 250, iOS=200, Android=300}"
    HeightRequest="{OnPlatform 250, iOS=200, Android=300}"
                IsVisible="{OnPlatform false,WinUI=true}"
    HorizontalOptions="Center" />
    

    Best Regards,

    Alec Liu.


    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

0 additional answers

Sort by: Most helpful

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.