Fix The nodes of TreeView not in dark mode when editing it - #14787
Fix The nodes of TreeView not in dark mode when editing it#14787Sathish-087 wants to merge 5 commits into
Conversation
|
Nice one! |
There was a problem hiding this comment.
Pull request overview
Adds dark-mode color handling for native TreeView and ListView label editors.
Changes:
- Handles
WM_CTLCOLOREDITfor active label-edit controls. - Applies parent foreground/background colors.
- Adds regression tests for both controls.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
TreeView.cs |
Colors the native node label editor. |
ListView.cs |
Colors the native item label editor. |
TreeViewTests.cs |
Tests TreeView editor colors. |
ListViewTests.cs |
Tests ListView editor colors. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if (editHwnd == HWND.Null) | ||
| { | ||
| PInvokeCore.SendMessage(listView, PInvoke.LVM_CANCELEDITLABEL); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Updated the test to use an assertion instead of returning early. This ensures the edit control is created and the dark mode behavior is actually validated.
| if (editHwnd == HWND.Null) | ||
| { | ||
| treeView.Nodes[0].EndEdit(cancel: true); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Updated the test to use an assertion instead of returning early. This ensures the edit control is created and the dark mode behavior is actually validated.
KlausLoeffelmann
left a comment
There was a problem hiding this comment.
Looks even better now, let's take this!
|
@Sathish-087, can you merge this when you get the chance? Thanks! |
|
Hi @KlausLoeffelmann, I don't have merge access for this repository, so I'm unable to merge the PR. |
Fixes #12042
Proposed changes
WM_CTLCOLOREDITinTreeView.WndProcfor the native in-place node label edit control.WM_CTLCOLOREDITinListView.WndProcfor the native in-place item label edit control to maintain consistent dark-mode behavior.InitializeDCForWmCtlColorinfrastructure to apply the correct foreground and background colors to the native edit control during label editing.Customer Impact
Regression?
Risk
WM_CTLCOLOREDITpath for native label-edit controls and reuses the existingInitializeDCForWmCtlColorimplementation already used throughout WinForms color initialization logic.Screenshots
Before
TreeViewEditIssue.mp4
After
TreeViewEditFixDemo.mp4
Test methodology
TVN_BEGINLABELEDITWcreates a native edit control and thatWM_CTLCOLOREDITis raised by the edit control during painting.WM_CTLCOLOREDITtoInitializeDCForWmCtlColorcorrectly applies the control'sForeColorandBackColor.TreeViewandListViewunder dark mode and verified that text and background colors match the parent control.Accessibility testing
Test environment(s)
Microsoft Reviewers: Open in CodeFlow