nicetomitja
nicetomitja

Reputation: 205

.NET MAUI: Change off color of switch

is there an opportunity to change the off color of a switch control? I can change ThumbColor or OnColor, but unfortunately not OffColor.

When switch is not toggled, you can't see the complete switch control very good: Example

Thank you!

Upvotes: 2

Views: 3715

Answers (2)

Brian.S
Brian.S

Reputation: 137

Try something like this, when the switch is toggled change the colours. The initial colours based on your default can be set in OnAppearing().

In xaml.

<Switch BackgroundColor="#f9f9f9" IsToggled="{Binding ActiveFlightText}" OnColor="LightGreen" Toggled="sendActiveText_Toggled" />enter code here

And in code behind:

private void sendActiveText_Toggled(object sender, ToggledEventArgs e)
{
    Switch activeText = (Switch)sender;

    if(activeText.IsToggled)
    {
        activeText.ThumbColor = Colors.Green;
    }
    else
    {
        activeText.ThumbColor = Colors.Red;
    }
}:

Upvotes: 0

Jessie Zhang -MSFT
Jessie Zhang -MSFT

Reputation: 13803

When switch is not toggled, you can't see the complete switch control very good.

The background color set for the switch affects the visual effect.

You can try to set to another color.

Please refer to the following code:

        <Switch OnColor="Orange"  
                BackgroundColor="WhiteSmoke"
                ThumbColor="Green" 
                Toggled="Switch_Toggled" />

Upvotes: 1

Related Questions