Skip to content

Fix MessageBox dialogs not adapting to dark mode in WPF Gallery#793

Open
amarinov-msft wants to merge 1 commit into
microsoft:mainfrom
amarinov-msft:amarinov/messagebox-darkmode
Open

Fix MessageBox dialogs not adapting to dark mode in WPF Gallery#793
amarinov-msft wants to merge 1 commit into
microsoft:mainfrom
amarinov-msft:amarinov/messagebox-darkmode

Conversation

@amarinov-msft

@amarinov-msft amarinov-msft commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary
Fixes an accessibility issue in the WPF Gallery Message Box page. Dialogs shown via System.Windows.MessageBox.Show(...) render as the native Win32 message box, which does not honor the app's Fluent ThemeMode. In Dark mode the dialog stays light, so its text renders below the 4.5:1 contrast minimum required by MAS 4.3.1 and is flagged by Accessibility Insights. This is a platform limitation: MessageBox.ShowCore calls the user32 MessageBox, and the Fluent theme has no template for it, so the dialog cannot adapt to the app theme.

Change
Sample Applications/WPFGallery/Controls/ThemedMessageBox.xaml  /  .xaml.cs
Add a Fluent-themed ThemedMessageBox (a WPF Window) that inherits the application theme, so it adapts to Light/Dark/High Contrast automatically. It reuses the platform's own message-box brushes (MessageBoxBackground, MessageBoxForeground, MessageBoxSeparatorBorderBrush, MessageBoxTopOverlay) and SymbolThemeFontFamily for the severity icon.

Sample Applications/WPFGallery/Views/System/MessageBoxPage.xaml.cs 
Route the page's 7 dialog call sites through ThemedMessageBox instead of System.Windows.MessageBox.

Result
In Dark mode the message-box dialogs now render with the app's dark background and full-contrast Fluent foreground. Light and High Contrast appearance follow the app theme as well. Button semantics and returned MessageBoxResult values are preserved.

Testing

  • Built WPFGallery.csproj (0 errors).
  • Verified the Message Box page dialogs under Dark mode and confirmed buttons, default/cancel behavior, and return values match the previous dialogs.
  • Verified changing through Dark/Light modes
Microsoft Reviewers: Open in CodeFlow

The native Win32 MessageBox does not honor the app's Fluent ThemeMode, so dialogs stayed light in dark mode and failed contrast requirements. Add a Fluent-themed ThemedMessageBox (WPF Window) that inherits the app theme and route the MessageBox page's dialogs through it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant