Enable DataGridView dark mode theming via AppContext switch#14267
Open
LeafShi1 wants to merge 9 commits intodotnet:mainfrom
Open
Enable DataGridView dark mode theming via AppContext switch#14267LeafShi1 wants to merge 9 commits intodotnet:mainfrom
LeafShi1 wants to merge 9 commits intodotnet:mainfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #14267 +/- ##
===================================================
- Coverage 77.18395% 77.16791% -0.01604%
===================================================
Files 3279 3279
Lines 645138 645263 +125
Branches 47730 47755 +25
===================================================
- Hits 497943 497936 -7
- Misses 143503 143631 +128
- Partials 3692 3696 +4
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
…Color.get' and 'set' to public API
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces dark mode theming for the DataGridView control via an AppContext switch (System.Windows.Forms.DataGridViewDarkModeTheming), defaulting to enabled for .NET 10+. The changes provide better visual appearance and contrast in dark mode while preserving opt-out capability for backward compatibility.
Changes:
- Added AppContext switch to control DataGridView dark mode theming, with inheritance through style system
- Implemented dark mode rendering for multiple cell types including link cells, combo box cells, checkbox cells, and column header sort glyphs
- Added shared dark mode link colors to LinkUtilities for consistent link rendering across the DataGridView
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 31 comments.
Show a summary per file
| File | Description |
|---|---|
| src/System.Windows.Forms.Primitives/src/System/LocalAppContextSwitches/LocalAppContextSwitches.cs | Added DataGridViewDarkModeTheming switch with .NET 10+ default |
| src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs | Added dark mode color constants for links |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewLinkCell.cs | Implemented dark mode link colors with proper selection handling |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewComboBoxCell.DataGridViewComboBoxCellRenderer.cs | Added dark mode rendering for combo box dropdown and readonly buttons |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewColumnHeaderCell.cs | Refactored sort glyph rendering to support solid white glyphs in dark mode |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewCheckBoxCell.cs | Switched to CheckBoxRenderer.DrawCheckBoxWithVisualStyles for dark mode support |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewCellStyle.cs | Added SortGlyphColor property to allow customization of sort arrow color |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewCell.cs | Enhanced GetContrastedColors to provide better contrast in dark mode |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridView.Methods.cs | Added ApplyDarkModeTheming method and integration in OnHandleCreated |
| src/System.Windows.Forms/PublicAPI.Unshipped.txt | Documented new SortGlyphColor public API |
...ows/Forms/Controls/DataGridView/DataGridViewComboBoxCell.DataGridViewComboBoxCellRenderer.cs
Show resolved
Hide resolved
...tem.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewColumnHeaderCell.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridView.Methods.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewCell.cs
Outdated
Show resolved
Hide resolved
...ows/Forms/Controls/DataGridView/DataGridViewComboBoxCell.DataGridViewComboBoxCellRenderer.cs
Outdated
Show resolved
Hide resolved
...tem.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewColumnHeaderCell.cs
Show resolved
Hide resolved
...tem.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewColumnHeaderCell.cs
Show resolved
Hide resolved
...tem.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewColumnHeaderCell.cs
Show resolved
Hide resolved
...tem.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewColumnHeaderCell.cs
Show resolved
Hide resolved
...ystem.Windows.Forms.Primitives/src/System/LocalAppContextSwitches/LocalAppContextSwitches.cs
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14266
Proposed changes
System.Windows.Forms.DataGridViewDarkModeTheming(exposed via LocalAppContextSwitches / AppContextSwitches) to control whether DataGridView uses dark-mode-specific theming, defaulting to enabled for .NET 10 and allowing apps to opt out.ApplyDarkModeThemingin DataGridView and call it only when dark mode is active and the new switch is enabled, centralizing the dark palette (background, gridlines, header/row colors) for high contrast on dark backgrounds.LinkUtilitieslink colors (aligned with LinkLabel’s dark colors) and ensuring selected links render with appropriate selection foreground color for sufficient contrast.Customer Impact
Regression?
Risk
Screenshots
Before
After
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow