Skip to content

[Switch] Switch Toggle: OnColor Not set correctly and ThumbColor Not Reset When Toggled Off #19883

Closed

Description

@MAUIoxo

Description

I have a Switch in a Grid within a DataTemplate of a CollectionView with my own ThumbColor defined like in the example below:

<CollectionView.ItemTemplate>
    <DataTemplate x:DataType="{x:Type databaseModels:Band}">
        <Grid ColumnDefinitions="*, Auto" RowDefinitions="Auto" Padding="{OnPlatform Default='5, 0, 5, 0', iOS='5, 0, 5, 15'}">
            <Label Grid.Row="0" Grid.Column="0" Text="{Binding Band.Name}" VerticalOptions="Center" />
            <Switch Grid.Row="0" Grid.Column="1" IsEnabled="True" IsToggled="{Binding IsSelected, Mode=TwoWay}" ThumbColor="{StaticResource Gray100}" OnColor="{StaticResource Orange}" VerticalOptions="Center" HorizontalOptions="Center" Margin="{OnPlatform Android='0, -5, 0, -5'}"/>
        </Grid>
    </DataTemplate>
</CollectionView.ItemTemplate>

Initially the Switch looks like below:

grafik

First of all, when the Switch is toggled, it gets its defined wrong OnColor (should be Orange):

grafik

After that when it is toggled off again, the defined ThumbColor="{StaticResource Gray100}" is not set back and the Switch looks as follows:

grafik

Steps to Reproduce

  1. Define a ThumbColor and an OnColor for a Switch
  2. See how the Color looks like when the Switch is not toggled initially
  3. Toggle the Switch and it will apply the wrong OnColor (should be Orange)
  4. Toggled again to state "Off" and it will not apply the defined ThumbColor again

In the linked example Project from repository:

  1. Launch project
  2. Click on the DotNetBot Icon
  3. Defined ThumbColor is visible
  4. Toggle switch on and color does not change to correct OnColor (should be Orange)
  5. Toggle switch off and color is changed to a system default color, but not the specified ThumbColor again

Hint: The View containing the Switch with the ThumbColor and OnColor is in ..\Pages\Views*BottomSheetContentView.xaml*

Link to public reproduction project repository

ThumbColorNotReset_19883

Version with bug

8.0.6-nightly.9863

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

7.0.101

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

By the time this issue was reported, I did not find a workaround.

On April 13th 2024, I found the simples way that solved it for me, by just using a CustomSwitch that derived from Switch and use this in my XAML which fixed it for me as you can see below.

Relevant log output

No response

Activity

  1. added
    t/bug
    on Jan 14, 2024
  2. changed the title [-][Switch] ThumbColor does not get set when Switch is toggled off[/-] [+][Switch] ThumbColor does not get set back when Switch is toggled off[/+] on Jan 15, 2024
  3. changed the title [-][Switch] ThumbColor does not get set back when Switch is toggled off[/-] [+][Switch] Switch Toggle: ThumbColor Not Reset When Toggled Off[/+] on Jan 15, 2024
  4. ghost added
    legacy-area-controls
    on Jan 15, 2024
  5. added
    area-xaml
    s/needs-repro
    on Jan 15, 2024
  6. jsuarezruiz commented on Jan 15, 2024

    @jsuarezruiz
    Contributor

    Could be related? #19882

  7. MAUIoxo commented on Jan 16, 2024

    @MAUIoxo
    Author

    I added an example project that shows this Bug: ThumbColorNotReset_19883

    I don't think that #19882 is related. The Switch is within a Grid, but the other Bug is about Grid.Resources that overwrite globally defined Styles (e.g. for Labels) completely when a property is defined as a Grid.Resource (intention e.g. define a HorizontalOption for all Labels within this Grid) and this is not the same here

  8. ghost added
    s/needs-attention
    on Jan 16, 2024
  9. ghost removed
    s/needs-repro
    on Jan 16, 2024
  10. changed the title [-][Switch] Switch Toggle: ThumbColor Not Reset When Toggled Off[/-] [+][Switch] Switch Toggle: OnColor Not set correctly and ThumbColor Not Reset When Toggled Off[/+] on Jan 17, 2024
  11. MAUIoxo commented on Jan 17, 2024

    @MAUIoxo
    Author

    First of all, I fooled myself by not choosing a more distinct OnColor and did not see that also the OnColor is not set! The OnColor should be Orange, but is not assigned. Can also be seen in the same project I attached

  12. 36 remaining items

  13. locked and limited conversation to collaborators on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-switcharea-xamlpartner/syncfusionplatform/androidplatform/ioss/needs-attentions/triageds/verifiedt/bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions