WPF MessageBox window style

Kyrylo M picture Kyrylo M · Mar 13, 2011 · Viewed 33.9k times · Source

How to apply the default Windows style to the standard MessageBox in WPF?

For example, when I execute next code:

MessageBox.Show("Hello Stack Overflow!", "Test", MessageBoxButton.OKCancel, 
    MessageBoxImage.Exclamation);

I'm getting message box:

enter image description here

But in WinForms everything is OK with style:

MessageBox.Show("Hello Stack Overflow!", "Test", MessageBoxButtons.OKCancel, 
    MessageBoxIcon.Exclamation);

enter image description here

Answer

Gimno picture Gimno · Mar 13, 2011

According to this page, WPF picks up the old styles for some of the controls.

To get rid of it, you have to create a custom app.manifest file (Add -> New item -> Application Manifest File) and paste the following code in it (right after the /trustInfo - Tag ):

<!-- Activate Windows Common Controls v6 usage (XP and Vista): -->
<dependency>
  <dependentAssembly>
    <assemblyIdentity
      type="win32"
      name="Microsoft.Windows.Common-Controls"
      version="6.0.0.0"
      processorArchitecture="*"
      publicKeyToken="6595b64144ccf1df"
      language="*"/>
  </dependentAssembly>
</dependency>

Then you have to compile your solution with this app.manifest (set it in the project properties -> Application -> Point to the new manifest in "Icons and manifest").

If you start your application now it should look like the WinForms- MessageBox.