Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF MessageBox window style

Tags:

c#

wpf

messagebox

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

like image 272
kyrylomyr Avatar asked Mar 13 '11 12:03

kyrylomyr


People also ask

How to Show MessageBox in WPF?

Simple MessageBox Clicking on the OK button closes the MessageBox. The following line of code uses the Show method to display a message box with a simple message: MessageBoxResult result = MessageBox. Show("Hello MessageBox");

Is MessageBox show a modal dialog window?

Displays a message window, also known as a dialog box, which presents a message to the user. It is a modal window, blocking other actions in the application until the user closes it. A MessageBox can contain text, buttons, and symbols that inform and instruct the user.

What is MessageBox class explain MessageBox () in detail?

A message box is a prefabricated modal dialog box that displays a text message to a user. You show a message box by calling the static Show method of the MessageBox class. The text message that is displayed is the string argument that you pass to Show.

What is message box in C#?

MessageBox is a class in C# and Show is a method that displays a message in a small window in the center of the Form. MessageBox is used to provide confirmations of a task being done or to provide warnings before a task is done. Create a Windows Forms app in Visual Studio and add a button on it.


1 Answers

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.

like image 180
Gimno Avatar answered Sep 24 '22 20:09

Gimno