wpf icon indicating copy to clipboard operation
wpf copied to clipboard

Apply Fluent Theme to WPF MessageBox

Open JackDjTom opened this issue 1 year ago • 10 comments

Since .NET 9 fluent theme is available for WPF. But the MessageBoxes still looks old.

Current MessageBox Style

Image

Expected MessageBox Style with fluent theme (Dialog from Microsoft Paint)

Image

JackDjTom avatar Feb 05 '25 21:02 JackDjTom

The MessageBox is a function of the OS and not of theming. Microsoft Paint is using custom-made dialogs and if you make your own dialogs too, they too can have a theme applied.

miloush avatar Feb 05 '25 22:02 miloush

MessageBox is just a wrapper around the Win32 control. WPF does not control the styling inside the MessageBox. You need an app mainfest to use the more modern controls (See https://github.com/dotnet/wpf/issues/5967#issuecomment-1017018189).

ThomasGoulet73 avatar Feb 05 '25 22:02 ThomasGoulet73

Note @ThomasGoulet73 that manifest does not help achieving the desired outcome here.

miloush avatar Feb 05 '25 23:02 miloush

@miloush Agreed, the message box won't be the same as Paint but it will be more modern.

ThomasGoulet73 avatar Feb 05 '25 23:02 ThomasGoulet73

And is there a good reason why WPF doesn't have a modern looking dialog system with custom controls? I can understand that Winforms uses WinAPIs for that. I can understand that WPF (1.0) used that. I don't understand why WPF in 2025 still uses WinAPI for this. What's wrong with a fluent message box? The way it would be implemented (opt-in, breaking change, new public API like FluentMessagebox etc) can be discussed later. But I think the question of whether something like this should be introduced in general is quite justified.

Symbai avatar Feb 06 '25 01:02 Symbai

@Symbai , what you are asking for, it is same as WinUI's ContentDialog or WinForm's TaskDialog API right ?

dipeshmsft avatar Feb 07 '25 06:02 dipeshmsft

I think the TaskDialog from WinForms also uses WinAPI. From screenshots its more like the ContentDialog although I have no experience with WinUI. Almost all styled WPF apps use a custom dialog / messagebox. And it shouldn't be too difficult. Its a simple WPF window which shows icons and buttons depending on how it was called. Like the existing MessageBox. But because its a WPF window it has the same style as the rest of your application.

And I don't think much more than this would be necessary for a "solution built into WPF". I wouldn't allow displaying custom content (controls). I also wouldn't make it a dialog which is centered on your app and draws a transparent shadow on its background. Instead just provide the same you can do with MessageBox already but put it into a WPF window so it has the same look as the rest. In this case: fluent.

Symbai avatar Feb 07 '25 08:02 Symbai

The problem here is that WPF MessageBoxes do not opt into visual styles - if you call System.Windows.Forms.Application.EnableVisualStyles(); and then use Windows Form's MessageBox, then you will get modern styled message boxes. You must enable UseWindowsForms in .NET or reference the Forms libraries in .NET Framework to do this.

You will then get a MessageBox that looks like this on Windows 11 (rounded corners on the buttons, modern icon, etc.): image

Ideally WPF could be updated to do whatever Forms does to opt into this.

I have written more about this here.

aquinn39 avatar Nov 13 '25 21:11 aquinn39

It is still not a fluid design, as OP requested.

Symbai avatar Nov 14 '25 03:11 Symbai

You must enable UseWindowsForms in .NET or reference the Forms libraries in .NET Framework to do this.

There is no need to do this, just include an application manifest. If you use the VS template for it, it contains the setting to be uncommented at the bottom.

This is documented here: https://learn.microsoft.com/en-us/windows/win32/controls/cookbook-overview

miloush avatar Nov 14 '25 09:11 miloush