Skip to content

Fix ComboBox dark mode theme on first TabPage#14578

Open
SimonZhao888 wants to merge 1 commit into
dotnet:mainfrom
SimonZhao888:Fix_issue_14107
Open

Fix ComboBox dark mode theme on first TabPage#14578
SimonZhao888 wants to merge 1 commit 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-DarkMode Issues relating to Dark Mode feature waiting-review This item is waiting on review by one or more members of team

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

2 participants