2

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!

nicetomitja
  • 145
  • 10

2 Answers2

1

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;
    }
}:
Brian.S
  • 131
  • 12
0

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" />
Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19
  • This is ok, but now I have a big white rectangle in background. So there is no possibility to only set the color of the switch control when its off? – nicetomitja Dec 07 '22 at 10:43
  • You can set the `BackgroundColor` property of `Switch` to the same or similar color of the background color of your page, then there will be no such rectangle. – Jessie Zhang -MSFT Dec 08 '22 at 03:22
  • 2
    `So there is no possibility to only set the color of the switch control when its off?` There is no such relative property for us to set for the switch control when its off. – Jessie Zhang -MSFT Dec 08 '22 at 03:24