Skip to content

Fix ComboBox dark mode theme on first TabPage - #14578

Merged
SimonZhao888 merged 2 commits into
dotnet:mainfrom
SimonZhao888:Fix_issue_14107
Sep 1, 2026
Merged

SimonZhao888 merged 2 commits into
dotnet:mainfrom
SimonZhao888:Fix_issue_14107

Conversation

@SimonZhao888

@SimonZhao888 SimonZhao888 commented May 29, 2026 •

Copy link
Copy Markdown
Member

Fixes #14107

Proposed changes

  • Modified TabControl.StyleChildren() to only apply dark mode theme to direct children (TabPages), not descendant controls
  • Added parent check using PInvoke.GetParent() to identify direct children
  • Preserved return value of SetWindowTheme() for proper error handling

Customer Impact

  • ComboBox controls on the first TabPage now correctly display in dark mode
  • Affects applications using Application.SetColorMode(SystemColorMode.Dark) with TabControl containing ComboBox controls

Regression?

  • Yes (regression from .NET 9.0)

Risk

  • Low. Surgical fix changes only theme application scope in TabControl
  • Only affects dark mode rendering path
  • Controls with specific dark mode themes (ComboBox, etc.) now preserve their themes

Screenshots

Before

Before fix - ComboBox on first tab shows light theme

After

image

Test methodology

  • Manual test

Test environment(s)

  • 11.0.100-preview.5.26227.104
Microsoft Reviewers: Open in CodeFlow

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a dark-mode regression where ComboBox controls placed on the first TabPage of a TabControl lost their specialized dark theming. TabControl.ApplyDarkModeOnDemand calls EnumChildWindows, which enumerates all descendant windows (not just direct children). The previous StyleChildren callback unconditionally applied DarkMode_Explorer to every descendant, overwriting the DarkMode_CFD theme that ComboBox.OnHandleCreated had set on itself. The fix scopes the theme application to direct children (i.e. TabPages) by comparing PInvoke.GetParent(handle) against the TabControl's HWND.

Changes:

  • Guard StyleChildren so SetWindowTheme(DarkMode_Explorer) is only applied when the enumerated handle's native parent is the TabControl itself.
  • Return true for non-direct descendants so enumeration continues, leaving control-specific dark themes (e.g. ComboBox) intact.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SimonZhao888

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@SimonZhao888 SimonZhao888 added the waiting-review This item is waiting on review by one or more members of team label Jun 15, 2026
@SimonZhao888
SimonZhao888 marked this pull request as draft August 14, 2026 07:39
@SimonZhao888 SimonZhao888 added the draft draft PR label Aug 14, 2026
@SimonZhao888
SimonZhao888 marked this pull request as ready for review August 17, 2026 09:37
@SimonZhao888 SimonZhao888 removed the draft draft PR label Aug 17, 2026

@KlausLoeffelmann KlausLoeffelmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@SimonZhao888
SimonZhao888 merged commit 8f11081 into dotnet:main Sep 1, 2026
8 checks passed
@SimonZhao888
SimonZhao888 deleted the Fix_issue_14107 branch September 1, 2026 01:05
@dotnet-policy-service dotnet-policy-service Bot removed the waiting-review This item is waiting on review by one or more members of team label Sep 1, 2026
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 1, 2026
abineshPalanisamy pushed a commit to abineshPalanisamy/winforms that referenced this pull request Sep 3, 2026
Co-authored-by: Simon Zhao (BEYONDSOFT CONSULTING INC) <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-DarkMode Issues relating to Dark Mode feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Dark Mode] the combobox refuses dark theme when on first tabpage of a tabcontrol

3 participants