Repository navigation
Fix ToggleSwitch checked thumb color in light and dark modes - #15270
SimonZhao888 merged 8 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Focus shading and contrast regressions remain unresolved, and the new rendering behavior lacks targeted regression tests.
3 open findings
What changed in this PR
Updates the shared ToggleSwitch renderer for CheckBox and RadioButton to address #15125 with theme-specific checked-thumb colors.
Changes:
- Uses white checked thumbs in light mode and black in dark mode.
- Blends unchecked and checked thumb colors during transitions.
- Preserves High Contrast and disabled-state rendering.
| File | Description |
|---|---|
| src/System.Windows.Forms/System/Windows/Forms/Rendering/CheckBox/AnimatedToggleSwitchRenderer.cs | Changes thumb-color selection and animation blending. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15270 +/- ##
=============================================
Coverage 37.84861% 37.84861%
=============================================
Files 246 246
Lines 9789 9789
Branches 1031 1031
=============================================
Hits 3705 3705
Misses 5920 5920
Partials 164 164
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
…color excluding any focus shadows
…-logical-pixel gap from the corresponding inner border; this gap scales with DPI.
|
This PR is primarily described as a color fix, but GetThumbBounds also changes the thumb's resting positions and reduces its travel distance. Could we either document why this geometry change is required for the color fix? And should add coverage for 100%, 150%, and 200% DPI, RTL, hover, and unusually small switch bounds. |
The geometry change is intentional and related to the contrast fix. Without the inset, the thumb can touch the edge of the track and become directly adjacent to the parent control’s background. In dark mode, this can leave insufficient contrast between the thumb and that background. The inset keeps track color between them, and the resulting geometry is also intended to more closely match the Windows toggle-switch UI. I’ve added automated coverage for 100%, 150%, and 200% DPI, LTR/RTL, checked/unchecked states, hover, intermediate animation positions, and unusually small control bounds. The tests verify resting positions, travel distance, and the preserved gap. |
|
Yes - the inset was off, my bad, and I absolute 2nd it! Could you also do me one favor: |
…15270) * Fix ToggleSwitch checked thumb color in light and dark modes * Add unite test and update code floowing by the suggestion * In the "checked" state, the border and the track use the same color * Determine the contrast between the slider and the track based on the color excluding any focus shadows * When the slider is at either the left or right endpoint, there is a 2-logical-pixel gap from the corresponding inner border; this gap scales with DPI. * Ensure focus-shaded track meets minimum contrast * Add DPI tests * Fix test failure


Fixes #15125
Root cause
The ToggleSwitch renderer selected the thumb color dynamically based on the current track color. As a result, the checked thumb could become black or white depending on the configured accent color rather than following the Windows theme-specific color behavior.
This caused inconsistent rendering across accent colors: the checked thumb could appear black in Light Mode or white in Dark Mode.
Proposed changes
Customer Impact
Appearance.ToggleSwitchwill render checked CheckBox and RadioButton thumbs consistently with the corresponding Windows color mode.Regression?
Risk
Screenshots
Before
The checked thumb color was dynamically selected according to its contrast with the track.
LightMode:
LightMode_beforeChanges.mp4
DarkMode:
DarkMode_beforeChanges.mp4
After
Light Mode always renders the checked thumb in white. Dark Mode always renders the checked thumb in black.
LightMode:

DarkMode:

Test methodology
Test environment(s)