问题描述
如何将默认的Windows样式应用到WPF中的标准的MessageBox
?
How to apply the default Windows style to the standard MessageBox
in WPF?
例如,当我执行下code:
For example, when I execute next code:
MessageBox.Show("Hello Stack Overflow!", "Test", MessageBoxButton.OKCancel,
MessageBoxImage.Exclamation);
我得到的消息框:
I'm getting message box:
但在WinForms的一切都OK的风格:
But in WinForms everything is OK with style:
MessageBox.Show("Hello Stack Overflow!", "Test", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);
推荐答案
据this页面,WPF拿起旧样式一些控制。
According to this page, WPF picks up the old styles for some of the controls.
要摆脱它,你必须创建一个自定义app.manifest文件(添加 - >新建项目 - >应用程序清单文件),并粘贴以下code在它(/ trustInfo之后 - 标签)
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>
然后,你有这个app.manifest编译您的解决方案(将其设置在项目属性 - >应用程序 - >指向新的体现在图标和清单)。
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").
如果你现在就开始你的应用程序应该看起来像WinForms-消息框。
If you start your application now it should look like the WinForms- MessageBox.
这篇关于WPF的MessageBox窗口样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!