更改 WPF 应用程序清单?
我向 Microsoft 发布了 一条评论,指出 WPF 中的对话框未启用 VisualStyle。
乔·卡斯特罗在那里发布了一个解决方法,我不太明白如何实现,有人可以帮忙吗?
以下是他的回复:
出于应用程序兼容性的原因,应用程序默认情况下不使用系统通用控件的 v6(自 XP 起可用)。这实际上并不适用于 WPF,但您也仅在使用本机控件时在少数情况下看到它,因此它不像 WinForms 那样普遍,因为 WinForms 的 API 只是包装标准控件。
要在 WPF 中修复此问题,您需要通过在 exe 的清单中指定它来显式选择加入 v6 comctl32。这必须在 exe 上完成,因此 WPF 无法将其作为 DLL 的一部分来完成。 EnableVisualStyles 在运行时执行此操作,但这种方式通常更好。
例如,类似:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<description>MyExe.exe</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"/>
</dependentAssembly>
</dependency>
</assembly>
I posted a comment to Microsoft that the Dialog Boxes in WPF are not VisualStyle enabled.
Joe Castro posted a workaround there which I don't really understand how to achieve, can anyone help?
Here is he's response:
For app compat reasons applications don't by default use v6 of the system common controls (available since XP). This doesn't really apply to WPF, but you also only see it in a few situations when using the native controls so it's not as prevalent as WinForms where their APIs are just wrapping the standard controls.
To fix this in WPF you need to explicitly opt-in to v6 comctl32 by specifying it in a manifest in your exe. This has to be done on the exe, so WPF can't do it as part of their DLLs. EnableVisualStyles does this at runtime but this way is generally better.
E.g., something like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<description>MyExe.exe</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"/>
</dependentAssembly>
</dependency>
</assembly>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我前段时间在博客上写过:
这些帖子描述了问题和解决方案:http://www.nbdtech.com/blog/archive/2008/05/28/Why-am-I- Getting-Old-Style-File-Dialogs-and-Message.aspx , http://www.nbdtech.com/blog/archive/2008/06/08/Will-Setting-a- Manifest-Solve-My-WPF-Message-Box-Style.aspx
这篇文章就是您正在寻找的内容:http://www.nbdtech.com/blog/archive/2008/06/ 16/The-Application-Manifest-Needed-for-XP-and-Vista-Style-File.aspx
这讨论了如何获取文件打开和保存对话框的 Vista 样式:http: //www.nbdtech.com/blog/archive/2008/07/15/Vista-style-open-and-save-dialogs-with-WPF-without-using.aspx
I wrote about it on my blog some time ago:
Those posts describe the problem and the solution: http://www.nbdtech.com/blog/archive/2008/05/28/Why-am-I-Getting-Old-Style-File-Dialogs-and-Message.aspx , http://www.nbdtech.com/blog/archive/2008/06/08/Will-Setting-a-Manifest-Solve-My-WPF-Message-Box-Style.aspx
This post is what you are looking for : http://www.nbdtech.com/blog/archive/2008/06/16/The-Application-Manifest-Needed-for-XP-and-Vista-Style-File.aspx
And this talks about how to get the Vista style for file open and save dialogs: http://www.nbdtech.com/blog/archive/2008/07/15/Vista-style-open-and-save-dialogs-with-WPF-without-using.aspx
在 Visual Basic 中,项目属性的结构略有不同。如果您发现此问题并且您使用的是 VS2010 中的 VB,请按照以下说明生成 app.manifest 文件。
进一步阅读: WPF MessageBox 窗口样式
In Visual Basic, the project properties are structured a little differently. If you find this question and you're in VB in VS2010, follow these instructions to generate an app.manifest file.
Further Reading: WPF MessageBox window style