WPF MessageBox 按钮不是操作系统主题
因此,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是 WPF 中的一个奇怪的故障,它缺少激活视觉样式的管道。双奇数,因为这并不难做到。
解决方法是修改嵌入到程序中的清单。选择您的 EXE 项目,然后选择“项目 + 添加新项目”、“常规”,选择“应用程序清单文件”。您将获得嵌入的默认清单,请注意
和
元素。将其粘贴到两者之间:消息框现在将具有操作系统的视觉样式,在 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: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.
您所做的更改已保存,但在 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).
您可以尝试使用 http://elegantcode.com/ 2010/08/05/extended-wpf-toolkit-new-messagebox-control/ - 代码发布在 http: //wpftoolkit.codeplex.com/
更多文档还位于 http:// /wpftoolkit.codeplex.com/wikipage?title=MessageBox&referringTitle=Home
You could try using http://elegantcode.com/2010/08/05/extended-wpf-toolkit-new-messagebox-control/ - code posted within http://wpftoolkit.codeplex.com/
More documentation also on http://wpftoolkit.codeplex.com/wikipage?title=MessageBox&referringTitle=Home