I am working with .NET MAUI on Windows (WinUI) and using the default Switch, which maps to ToggleSwitch.
I am trying to achieve consistent styling for different switch states, but I am facing issues where the control falls back to white background unexpectedly.
It seems like Visual States are not being applied correctly in certain scenarios. The default colors applying instead of my visual state colors.
Problem
Case 1:
Expected:
- Light gray (disabled OFF state)
Actual:
- White / washed out background
Case 2:
On hover (PointerOver):
Expected:
- Slightly darker gray (hover effect)
Actual:
- White background appears on hover
Attempted but failed
public class CustomSwitchHandler : SwitchHandler
{
protected override void ConnectHandler(ToggleSwitch platformView)
{
base.ConnectHandler(platformView);
platformView.Resources["ToggleSwitchFillOff"] =
new SolidColorBrush(Colors.Gray);
platformView.Resources["ToggleSwitchFillOffPointerOver"] =
new SolidColorBrush(Colors.DarkGray);
platformView.Resources["ToggleSwitchFillOffDisabled"] =
new SolidColorBrush(Colors.LightGray);
}
}
Why does the ToggleSwitch show white background for:
IsEnabled = false,IsToggled = falseHover (PointerOver) when
IsToggled = falseExpected Result
OFF (enabled) → gray
OFF (hover) → darker gray (no white)
OFF (disabled) → light gray (no white/fading)
How to achieve the expected result?