Fix issue 14198: [Dark Mode] Improve visual contrast of the Group Headers in ListView control in dark#14406
Open
SimonZhao888 wants to merge 2 commits intodotnet:mainfrom
Open
Fix issue 14198: [Dark Mode] Improve visual contrast of the Group Headers in ListView control in dark#14406SimonZhao888 wants to merge 2 commits intodotnet:mainfrom
SimonZhao888 wants to merge 2 commits intodotnet:mainfrom
Conversation
…ders in ListView control in dark
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets WinForms ListView dark mode rendering by improving the visual contrast of group headers (and related group text) when groups are enabled.
Changes:
- Adds custom dark-mode rendering logic for group header text, chevron, subtitle, and footer.
- Adjusts custom-draw flags and text color handling to receive group-related draw notifications and control group text colors.
- Updates the applied dark-mode theme identifier for the ListView/ColumnHeader to use the ItemsView theme.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/System.Windows.Forms/System/Windows/Forms/Controls/ListView/ListView.cs
Outdated
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
Contributor
There was a problem hiding this comment.
Pull request overview
Improves ListView group header readability in dark mode by adjusting theming/custom-draw behavior and adding an overlay render pass to redraw group header/subtitle/footer with higher-contrast styling.
Changes:
- Add dark-mode overlay drawing for group header/subtitle/footer and a custom chevron/underline rendering path.
- Adjust ListView custom draw flags/colors so group custom-draw notifications are raised and native group text is suppressed in dark mode.
- Switch the applied dark-mode theme identifier to
DarkMode_ItemsViewand attempt to configure group text colors viaLVM_SETGROUPMETRICS.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+271
to
+276
| using Pen chevronPen = new(chevronColor, 2.6f) | ||
| { | ||
| StartCap = Drawing.Drawing2D.LineCap.Round, | ||
| EndCap = Drawing.Drawing2D.LineCap.Round, | ||
| LineJoin = Drawing.Drawing2D.LineJoin.Round | ||
| }; |
Comment on lines
+297
to
+301
| using Pen linePen = new(lineColor, 1f) | ||
| { | ||
| StartCap = Drawing.Drawing2D.LineCap.Round, | ||
| EndCap = Drawing.Drawing2D.LineCap.Round | ||
| }; |
Comment on lines
+174
to
+175
| int headerTextX = isRtl ? headerRect.Right - horizontalPadding - headerTextWidth | ||
| : headerRect.Left + horizontalPadding; |
Comment on lines
+254
to
+261
| int centerX = headerRect.Right - 9; | ||
| int centerY = headerTextRect.Top + (headerTextRect.Height / 2) + 1; | ||
|
|
||
| Rectangle nativeChevronRect = new( | ||
| headerRect.Right - 24, | ||
| headerTextRect.Top - 3, | ||
| 24, | ||
| headerTextRect.Height + 8); |
Comment on lines
6262
to
+6280
| if (Application.IsDarkModeEnabled | ||
| && !OwnerDraw | ||
| && nmhdr->code == PInvoke.NM_CUSTOMDRAW) | ||
| { | ||
| NMLVCUSTOMDRAW* nmlvcd = (NMLVCUSTOMDRAW*)(nint)m.LParamInternal; | ||
|
|
||
| if (nmlvcd->nmcd.dwDrawStage == NMCUSTOMDRAW_DRAW_STAGE.CDDS_PREPAINT) | ||
| { | ||
| // We request the notification for the items to be drawn. | ||
| m.ResultInternal = (LRESULT)(nint)PInvoke.CDRF_NOTIFYITEMDRAW; | ||
| return true; | ||
| } | ||
| else if (nmlvcd->nmcd.dwDrawStage == NMCUSTOMDRAW_DRAW_STAGE.CDDS_ITEMPREPAINT) | ||
| { | ||
| // Setting the current ForeColor to the text color. | ||
| PInvokeCore.SetTextColor(nmlvcd->nmcd.hdc, ForeColor); | ||
| Color textColor = nmlvcd->dwItemType == NMLVCUSTOMDRAW_ITEM_TYPE.LVCDI_GROUP | ||
| ? BackColor | ||
| : ForeColor; | ||
|
|
||
| PInvokeCore.SetTextColor(nmlvcd->nmcd.hdc, textColor); |
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 #14198
Proposed changes
Customer Impact
Regression?
Risk
Screenshots
Before
After
Test methodology
Accessibility testing
Test environment(s)