WPF MessageBox 按钮不是操作系统主题

发布于 2024-10-24 16:55:34 字数 280 浏览 5 评论 0原文

因此,WPF 中消息框的按钮不是由操作系统主题的。
我什至尝试了这种方法但它不起作用。

我有一个清单,我在 Windows 7 Ultimate x86 和 .NET Framework 4 Client Profile 下运行。


编辑:现在可以使用了。

So the buttons of my message box in WPF aren't themed by the OS.
I even tried this method and it didn't work.

I have a manifest, I am running under Windows 7 Ultimate x86 and .NET Framework 4 Client Profile.


EDIT: It works now.

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

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

发布评论

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

评论(3

萌化 2024-10-31 16:55:34

这是 WPF 中的一个奇怪的故障,它缺少激活视觉样式的管道。双奇数,因为这并不难做到。

解决方法是修改嵌入到程序中的清单。选择您的 EXE 项目,然后选择“项目 + 添加新项目”、“常规”,选择“应用程序清单文件”。您将获得嵌入的默认清单,请注意 元素。将其粘贴到两者之间:

  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>

消息框现在将具有操作系统的视觉样式,在 Vista 及更高版本上默认情况下带有发光关闭按钮的 Aero 外观。

如果您在 Visual Studio 2010 中执行此操作,则此清单条目已存在,但已被注释掉。您会在文件底部找到它。只需删除注释, 之前的 dependency>

请注意,当您在启用调试器和 Visual Studio 托管进程的情况下运行时,不会启用此清单。这是构建目录中的另一个 .exe 文件,yourapp.vshost.exe。 “项目 + 属性”、“调试”选项卡,向下滚动,取消选中“启用 Visual Studio 托管进程”。这有一些与安全相关的副作用,实际上这样做没有多大意义,因为您的用户永远不会遇到这个问题。

This is an odd glitch in WPF, it is missing the plumbing to activate visual styles. Doubly-odd because this isn't hard to do.

The workaround is modify the manifest that gets embedded in your program. Select your EXE project, then Project + Add New Item, General, select Application Manifest File. You get the default manifest that gets embedded, note the <assemblyIdentity> and <trustInfo> elements. Paste this in between:

  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>

The message box will now have the operating system's visual style, the Aero look with the glowing close button by default on Vista and up.

If you do this in Visual Studio 2010 then this manifest entry is already present but is commented out. You'll find it at the bottom of the file. Just remove the comments, the <!-- before <dependency> and the --> after </dependency>

Beware that this manifest is not enabled when you run with the debugger and the Visual Studio hosting process enabled. That's a different .exe file in your build directory, yourapp.vshost.exe. Project + Properties, Debug tab, scroll down, untick "Enable the Visual Studio hosting process". That has a few side effects related to security, there isn't much point in actually doing this since your user will never have this problem.

情徒 2024-10-31 16:55:34

您所做的更改已保存,但在 VS 中调试时无法查看它们。要解决此问题,请右键单击您的项目并单击“属性”,然后转到“调试”。页面底部有一个名为“启用 Visual Studio 托管进程”的复选框 - 取消选中此复选框。建议您在进行此更改后重新启动 Visual Studio。

或者,您可以直接构建而不进行调试 (CTRL+F5)。

The changes you've made have been saved but you cannot view them whilst debugging in VS. To fix this, right click your project and click "Properties" and then go to "Debug". There is a checkbox at the bottom of the page named "Enable the Visual Studio hosting process" - un-tick this. It is recommended that you restart visual studio after making this change.

Alternatively, you can just build without debugging (CTRL+F5).

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