Fix issue 14210: [Dark Mode] The ListView cannot display the items when setting the Enable as false#14219
Fix issue 14210: [Dark Mode] The ListView cannot display the items when setting the Enable as false#14219SimonZhao888 wants to merge 1 commit intodotnet:mainfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #14219 +/- ##
===================================================
+ Coverage 77.15694% 77.17234% +0.01539%
===================================================
Files 3279 3279
Lines 645347 645064 -283
Branches 47721 47723 +2
===================================================
- Hits 497930 497811 -119
+ Misses 143729 143560 -169
- Partials 3688 3693 +5
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This pull request addresses issue #14210 where ListView items are not displayed correctly when the control is disabled (Enabled = false) in dark mode. The root cause is that the underlying Win32 ListView control has a light font color in dark mode but doesn't have its background color properly set to dark, making the items invisible or hard to see.
Changes:
- Adds conditional color handling in the CustomDraw method for disabled ListViews in dark mode
- Sets specific text and background colors to improve visibility when the control is disabled and dark mode is enabled
src/System.Windows.Forms/System/Windows/Forms/Controls/ListView/ListView.cs
Show resolved
Hide resolved
src/System.Windows.Forms/System/Windows/Forms/Controls/ListView/ListView.cs
Show resolved
Hide resolved
src/System.Windows.Forms/System/Windows/Forms/Controls/ListView/ListView.cs
Show resolved
Hide resolved
src/System.Windows.Forms/System/Windows/Forms/Controls/ListView/ListView.cs
Show resolved
Hide resolved
src/System.Windows.Forms/System/Windows/Forms/Controls/ListView/ListView.cs
Show resolved
Hide resolved
| if (Application.IsDarkModeEnabled && !Enabled && DarkModeRequestState is true) | ||
| { | ||
| nmcd->clrText = (COLORREF)ColorTranslator.ToWin32(SystemColors.ControlDarkDark); | ||
| nmcd->clrTextBk = (COLORREF)ColorTranslator.ToWin32(Color.FromArgb(255, 240, 240, 240)); |
There was a problem hiding this comment.
Is it necessary to set the text background separately?
Just a suggestion: Using InactiveCaptionText can make the disabled state more noticeable.
Fixes #14210
Root Cause
ListView is the underlaying Win32 control. When it's in dark mode, the font color is highlighted, but the background color isn't set to dark, causing the items in the ListView to not display correctly. Furthermore, we cannot modify the background color using following code
PInvokeCore.SendMessage(this, PInvoke.LVM_SETBKCOLOR, (WPARAM)0, (LPARAM)BackColor).Proposed changes
Customer Impact
Regression?
Risk
Screenshots
Before
After
Test methodology
Accessibility testing
Test environment(s)
Microsoft Reviewers: Open in CodeFlow