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:
But in WinForms everything is OK with style:
MessageBox.Show("Hello Stack Overflow!", "Test", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
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");
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With