Skip to content

Switch ThumbColor not Initialized Using VisualStateManager on iOS Device #33783

@fischberg

Description

@fischberg

Description

When I use VisualStateManager to set the ThumbColor on a Switch implicitly either in Styles.xaml or as a ContentPage.Resource, if the Switch is in the IsToggled state, the specific ThumbColor for the "On" state is ignored. If I toggle the switch off and back on again, the correct ThumbColor is applied. This only happens on an iOS device, not on an iOS Simulator. It happens for both Debug and Release builds.

Here is the Xaml code in Styles.xaml:

<Style TargetType="Switch"> <Setter Property="OnColor" Value="Green" /> <Setter Property="VisualStateManager.VisualStateGroups"> <VisualStateGroupList> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal" /> <VisualState x:Name="Disabled"> <VisualState.Setters> <Setter Property="ThumbColor" Value="{StaticResource Gray300}" /> </VisualState.Setters> </VisualState> <VisualState x:Name="On"> <VisualState.Setters> <Setter Property="ThumbColor" Value="Red" /> </VisualState.Setters> </VisualState> <VisualState x:Name="Off"> <VisualState.Setters> <Setter Property="ThumbColor" Value="{StaticResource Gray600}" /> </VisualState.Setters> </VisualState> </VisualStateGroup> </VisualStateGroupList> </Setter> </Style>

Here is the very simple code in code behind for the page were "testSwitch" is displayed:

namespace InitialSwitchColorIssue.Pages { public partial class MainPage : ContentPage { public MainPage(MainPageModel model) { InitializeComponent(); testSwitch.IsToggled = true; } } }

Steps to Reproduce

Simply build the app on an iOS device (I deployed on an iPhone 15 running 26.2.1.

When the iPhone in dark mode, when the MainPage is initially displayed, the ThumbColor is white. After toggling the switch off then on, the ThumbColor is Red.

Link to public reproduction project repository

https://github.com/fischberg/InitialSwitchColorIssue

Version with bug

9.0.111 SR11.1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

26.2.1 device only, works on simulator

Did you find any workaround?

Not yet. Tried using Triggers but that didn't solve the problem.

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions