Repository navigation
Description
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:
First of all, when the Switch is toggled, it gets its defined wrong OnColor (should be Orange):
After that when it is toggled off again, the defined ThumbColor="{StaticResource Gray100}" is not set back and the Switch looks as follows:
Steps to Reproduce
- Define a ThumbColor and an OnColor for a Switch
- See how the Color looks like when the Switch is not toggled initially
- Toggle the Switch and it will apply the wrong OnColor (should be Orange)
- Toggled again to state "Off" and it will not apply the defined ThumbColor again
In the linked example Project from repository:
- Launch project
- Click on the DotNetBot Icon
- Defined ThumbColor is visible
- Toggle switch on and color does not change to correct OnColor (should be Orange)
- 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
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
[-][Switch] ThumbColor does not get set when Switch is toggled off[/-][+][Switch] ThumbColor does not get set back when Switch is toggled off[/+][-][Switch] ThumbColor does not get set back when Switch is toggled off[/-][+][Switch] Switch Toggle: ThumbColor Not Reset When Toggled Off[/+]jsuarezruiz commentedon Jan 15, 2024
Could be related? #19882
MAUIoxo commentedon Jan 16, 2024
I added an example project that shows this Bug: ThumbColorNotReset_19883
I don't think that #19882 is related. The
Switchis within aGrid, but the other Bug is aboutGrid.Resourcesthat overwrite globally defined Styles (e.g. for Labels) completely when a property is defined as aGrid.Resource(intention e.g. define aHorizontalOptionfor all Labels within thisGrid) and this is not the same here[-][Switch] Switch Toggle: ThumbColor Not Reset When Toggled Off[/-][+][Switch] Switch Toggle: OnColor Not set correctly and ThumbColor Not Reset When Toggled Off[/+]MAUIoxo commentedon Jan 17, 2024
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
36 remaining items
[Testing] Refactoring Feature Matrix UITest Cases for Switch Control (#…
Fix Switch ThumbColor Not Reset to Null (#36750)
[Testing] Refactoring Feature Matrix UITest Cases for Switch Control (#…
Fix Switch ThumbColor Not Reset to Null (#36750)
[Testing] Refactoring Feature Matrix UITest Cases for Switch Control (#…
Fix Switch ThumbColor Not Reset to Null (#36750)
[Testing] Refactoring Feature Matrix UITest Cases for Switch Control (#…
Fix Switch ThumbColor Not Reset to Null (#36750)
[Testing] Refactoring Feature Matrix UITest Cases for Switch Control (#…
Fix Switch ThumbColor Not Reset to Null (#36750)
[Testing] Refactoring Feature Matrix UITest Cases for Switch Control (#…
Fix Switch ThumbColor Not Reset to Null (#36750)
[Testing] Refactoring Feature Matrix UITest Cases for Switch Control (#…