Skip to content

Add a themed dialog#2276

Merged
brianrob merged 1 commit intomicrosoft:mainfrom
JeremyKuhne:themedialog
Aug 18, 2025
Merged

Add a themed dialog#2276
brianrob merged 1 commit intomicrosoft:mainfrom
JeremyKuhne:themedialog

Conversation

@JeremyKuhne
Copy link
Member

@JeremyKuhne JeremyKuhne commented Aug 9, 2025

Theming isn't easy for the system message box and requires using undocumented APIs. To get theming, including a simple themed message box that roughly follows the existing layout.

Move the project to the standard SDK which enables using source generators. The existing SDK was a hack for building before WPF and WinForms were officially released on .NET Core.

Push the C# version to 12 for collections expressions, default parameters for lambdas, etc.

Add CsWin32 for PInvoke source generation. Add PInvokes for getting the modern shell icons for the new dialog. System.Drawing has the new Icons in .NET, but we're still targetting 4.6.2. (Note that some PInvokes have to still be manually defined because we're targetting AnyCPU. Some headers in Windows are defined with nonstandard packing, which makes the SDK generate metadata that is platform specific. For safety they don't generate any of these and they must be manually evaluated. The manual ones I added come from System.Drawing. If we targetted specific architectures this wouldn't be necessary.)

If we're able to move to .NET Core in the future we can get more explicit, coherent theming support through WPF or MAUI.

Existing:

Screenshot 2025-08-09 100920

Themed:
(The light version is not as fully realized, as the theme for that wasn't in the current sources, I did the bare minimum with the intent of following up on the theme sources at some point.)

Screenshot 2025-08-09 100956 Screenshot 2025-08-09 101140 Screenshot 2025-08-09 101033

(The preset dialog doesn't have a real preset string in it, just ran it in the about menu with version text to make sure it was working correctly.)

Theming isn't easy for the system message box and requires using undocumented APIs. To get theming, including a simple themed message box that roughly follows the existing layout.

Move the project to the standard SDK which enables using source generators. The existing SDK was a hack for building before WPF and WinForms were officially released on .NET Core.

Push the C# version to 12 for collections expressions, default parameters for lambdas, etc.

Add CsWin32 for PInvoke source generation. Add PInvokes for getting the modern shell icons for the new dialog. System.Drawing has the new Icons in .NET, but we're still targetting 4.6.2. (Note that some PInvokes have to still be manually defined because we're targetting AnyCPU. Some headers in Windows are defined with nonstandard packing, which makes the SDK generate metadata that is platform specific. For safety they don't generate any of these and they must be manually evaluated. The manual ones I added come from System.Drawing. If we targetted specific architectures this wouldn't be necessary.)

If we're able to move to .NET Core in the future we can get more explicit, coherent theming support through WPF or MAUI.
Copy link
Member

@brianrob brianrob left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @JeremyKuhne! Just to confirm - this does not use any undocumented APIs, right? I think I read from your description that the solution you used to avoid undocumented APIs is to create your own dialog, but just want to make sure.

@JeremyKuhne
Copy link
Member Author

LGTM. Thanks @JeremyKuhne! Just to confirm - this does not use any undocumented APIs, right? I think I read from your description that the solution you used to avoid undocumented APIs is to create your own dialog, but just want to make sure.

Yeah, I spun a custom one to avoid undocumented features.

Copy link
Member

@brianrob brianrob left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you @JeremyKuhne!

@brianrob brianrob merged commit 51c3343 into microsoft:main Aug 18, 2025
5 checks passed
@JeremyKuhne JeremyKuhne deleted the themedialog branch August 18, 2025 23:46
leculver added a commit to leculver/perfview that referenced this pull request Feb 19, 2026
The SecurityCheck callback runs on a background thread during symbol
resolution. PR microsoft#2276 replaced System.Windows.MessageBox (Win32-based,
no thread affinity) with XamlMessageBox (WPF-based, requires STA thread),
causing symbol lookup to fail with 'The calling thread must be STA'.

Fix by dispatching the XamlMessageBox.Show call to the UI thread via
GuiApp.MainWindow.Dispatcher.Invoke(), consistent with other
XamlMessageBox call sites in CommandProcessor.cs and PerfViewData.cs.

Fixes microsoft#2300

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.

3 participants