How to create Custom Themed Toggle Switch [Switch Class] (Microsoft.Maui.Controls)?

Soumyadip Majumder 100 Reputation points
2025-03-12T15:18:36.0533333+00:00

How can we design a custom themed toggle switch in .NET Maui with .NET 9;

As we know we can do it using C# to design the switch and call it in XAML

If somebody knows, please share your thoughts on this topic.

For reference I have shared two links of toggle switch designs.

https://i.ytimg.com/vi/priPsxNtZ-I/maxresdefault.jpg

https://img.freepik.com/premium-vector/download-upload-bar-illustration_6735-1139.jpg?w=2000

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

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2025-03-12T15:18:36.0666667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To create a custom themed toggle switch in .NET MAUI using the Switch class, you can define properties such as OnColor and ThumbColor to customize its appearance. You can instantiate the switch in XAML or C# and set these properties to achieve the desired theme.

    Here’s an example of how to create a themed toggle switch in XAML:

    <Switch OnColor="Orange" ThumbColor="Green" IsToggled="true"/>
    

    And in C#:

    Switch themedSwitch = new Switch 
    { 
        OnColor = Colors.Orange, 
        ThumbColor = Colors.Green, 
        IsToggled = true 
    };
    

    You can also define visual states for the switch to change its appearance based on the IsToggled property. This allows for a more dynamic and visually appealing design.

    For more advanced theming, you might consider using styles and templates to create a consistent look across your application.


    References:

    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.