如何设置 System.Windows.MessageBox 按钮的样式?

发布于 2024-08-06 19:13:31 字数 160 浏览 0 评论 0原文

我在 WPF 应用程序中使用 System.Windows.MessageBox,由于某种原因,其按钮的样式采用 Windows 2000 方式 - 不是 WinXP,不是 Aero,不是 WPF 默认值。只是灰色和基本的 3D 边框。

怎样才能让它们显得更现代呢? (其实哪一个并不重要)

I'm using System.Windows.MessageBox in a WPF app, and for some reason its buttons are styled the Windows 2000 way - not WinXP, not Aero, not the WPF default. Just gray with basic 3d borders.

How can I make them appear with a more modern style? (doesn't really matter which one)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又怨 2024-08-13 19:13:31

您可以使用清单修复此问题。请参阅本文以获取分步说明:为什么我使用 WPF 获得旧式文件对话框和消息框

基本上,您必须向应用程序添加一个名为“清单”的 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 对话框按钮将采用系统主题样式。

You can fix this with a manifest. See this article for step-by-step instructions: Why am I Getting Old Style File Dialogs and Message Boxes with WPF

Basically, you have to add an XML file called a 'manifest' to your application.

Update:

Actually, it is very easy to do this in VS2008. Go to Project Properties->Application and click the 'View UAC Settings' button. This will automatically create an application manifest file and open it. Edit this file as follows:

Just after the line:

</trustInfo>

Paste in the following dependency section:

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

My complete manifest looks like this:

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

After doing this, just build your app, run, and voila, the MessageBox dialog buttons take on the system theme style.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文