加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

wpf – 如何使System.Windows.MessageBox按钮设置样式?

发布时间:2020-12-14 01:36:26 所属栏目:Windows 来源:网络整理
导读:我在 WPF应用程序中使用System. Windows.MessageBox,由于某种原因,它的按钮采用Windows 2000方式设置 – 不是WinXP,不是Aero,不是WPF默认设置.只是灰色与基本的3d边框. 如何让它们以更现代的风格出现? (哪个真的不重要) 解决方法 您可以使用清单修复此问题.
我在 WPF应用程序中使用System. Windows.MessageBox,由于某种原因,它的按钮采用Windows 2000方式设置 – 不是WinXP,不是Aero,不是WPF默认设置.只是灰色与基本的3d边框.

如何让它们以更现代的风格出现? (哪个真的不重要)

解决方法

您可以使用清单修复此问题.有关分步说明,请参阅此文章: Why am I Getting Old Style File Dialogs and Message Boxes with WPF

基本上,您必须向应用程序添加一个名为“manifest”的XML文件.

更新:

实际上,在VS2008中很容易做到这一点.转到项目属性 – >应用程序,然后单击“查看UAC设置”按钮.这将自动创建一个应用程序清单文件并将其打开.编辑此文件如下:

就行之后:

</trustInfo>

粘贴在以下依赖关系部分:

<!-- 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>

我的完整清单看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <!-- Activate Windows Common Controls v6 usage (XP,Vista,Win 7) to support themed dialogs: -->
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>
</asmv1:assembly>

执行此操作后,只需构建您的应用程序,运行,然后,MessageBox对话框按钮将采用系统主题样式.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读