WPF MessageBox 窗口样式 [英] WPF MessageBox window style

查看:31
本文介绍了WPF MessageBox 窗口样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将默认的 Windows 样式应用到 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);

我收到消息框:

但是在 WinForms 中一切都很好:

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 文件(添加 -> 新项目 -> 应用程序清单文件)并将以下代码粘贴到其中(紧跟在/trustInfo - Tag 之后):

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-MessageBox.

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

这篇关于WPF MessageBox 窗口样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆