Enable visual styles for the MessageBox of WPF

Source: Internet
Author: User

Why is the MessageBox in WPF so

One of my classmates told me: "Is WPF not a new generation of technology?" How come the MessageBox doesn't look WinForm?

  

As a comparison of the messsagebox of Windows Forms with the MessageBox of WPF, we found that WPF does not have visual styles enabled.

Some friends will ask, since WPF does not have visual styles enabled, then why does its control look the same as when the style is enabled?

The reason is that WPF controls are drawn differently than normal programs, which are drawn with DirectX, and the MessageBox is calling the Windows API, so the MessageBox does not draw with DirectX, So we didn't see this visual style on the MessageBox.

Enable visual styles for WPF applications

As we all know, the Windows forms application calls a method in the Main method to enable visual styles:

Application.enablevisualstyles ();

For WPF we can use the application manifest file to solve this problem.

  

First, add an application manifest file to the project.

At the end of the manifest file, Microsoft has written for us to enable visual style code, and we just need to annotate it.

<!--Enable themes for Windows common Controls and Dialogs (Windows XP and later)-   <dependency>    < ;d ependentassembly>      <assemblyidentity          type= "Win32"          name= "Microsoft.windows.common-controls"          version= "6.0.0.0"          processorarchitecture= "*"          publickeytoken= "6595b64144ccf1df"          language= "*"        />    </dependentAssembly>  </dependency>

Rebuild the project, then run, the effect is as follows

  

Why still not? Landlord you Lie!!!

Don't worry, listen to me slowly.

We open the catalog generated by the application,

  

In this there are two exe, we run this generated WPFVisualStyle.WPF.exe, the effect is as follows, how, I did not lie to you?

  

Why is that?

OK, the problem is solved, pull something else. The following WPFVisualStyle.WPF.vshost.exe, looking at the name, knows that the host process is in Visual Studio debugger when it is not embedded in the manifest.

Some friends may ask, I would like to see the visual effect when debugging how to do?

In fact, just below the Debug tab of the project properties, find the Enable visual Studio hosting process, remove the previous tick, and the visual Studio will call WPFVisualStyle.WPF.exe when it's debugged, and we'll see visual effects.

About the application manifest file

Speaking so much, some friends may be interested in the application manifest file, about its usage, here is an MSDN document for your reference.

  Manifest Files Reference (Windows)

This article from Hamson Blog, the original address: http://www.cnblogs.com/hamson/archive/2013/02/18/enable-wpf-messagebox-visualstyle.html

Enable visual styles for the MessageBox of WPF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.