.net WPF 的 Windows 7 主题?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2075720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows 7 theme for WPF?
提问by devuxer
Is there any way to make a WPF app look like it's running on Windows 7 even if it's running on XP? I'm looking for some kind of theme I can just paste in. I'm aware of the themes project on Codeplex (https://archive.codeplex.com/?p=wpfthemes), but it lacks support for DataGrid, which is something I critically need. I was thinking maybe the Windows 7 theme would just be an easy port, or exists in some file somewhere already.
有没有办法让 WPF 应用程序看起来像在 Windows 7 上运行,即使它在 XP 上运行?我正在寻找某种我可以粘贴的主题。我知道 Codeplex ( https://archive.codeplex.com/?p=wpfthemes)上的主题项目,但它缺乏对 的支持DataGrid,即我非常需要的东西。我在想 Windows 7 主题可能只是一个简单的端口,或者已经存在于某个文件中。
Update
更新
Using @Lars Truijens idea, I was able to get the Windows 7 look for the major controls, but unfortunately it did not work for the WPF Toolkit DataGridcontrol, which I need.
使用@Lars Truijens 的想法,我能够在 Windows 7 中查找主要控件,但不幸的是它不适用于DataGrid我需要的 WPF Toolkit控件。
DataGridlooks like this with Aero theme
DataGrid看起来像这样的 Aero 主题


DataGridshouldlook like this
DataGrid应该看起来像这样


So, I'm still looking for a solution to this problem if anyone has any ideas. Maybe someone has built an extension to the Aero theme that covers the WPF toolkit controls? Again, any information you have is much appreciated.
因此,如果有人有任何想法,我仍在寻找解决此问题的方法。也许有人已经构建了涵盖 WPF 工具包控件的 Aero 主题扩展?同样,非常感谢您拥有的任何信息。
Update 2 - DataGrid Problem solved!
更新 2 - DataGrid 问题解决了!
To get the Aero theme to work with the DataGrid or any other WPF Toolkit controls, you just need to add a second Aero dictionary, so your App.xaml should now look like this.
要使 Aero 主题与 DataGrid 或任何其他 WPF Toolkit 控件一起使用,您只需添加第二个 Aero 字典,因此您的 App.xaml 现在应如下所示。
<Application.Resources>
...
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
<ResourceDictionary
Source="pack://application:,,,/WPFToolkit;component/Themes/Aero.NormalColor.xaml" />
...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Also, I would recommend turning the gridlines off in your DataGridcontrols (because they look horrible):
另外,我建议在您的DataGrid控件中关闭网格线(因为它们看起来很糟糕):
<DataGrid GridLinesVisibility="None" ...>
回答by Lars Truijens
WPF comes with the standard Windows themes on all Windows versions. For example, you can have the Aero theme (which Vista and Windows 7 use) on Windows XP with the following steps:
WPF 在所有 Windows 版本上都带有标准的 Windows 主题。例如,您可以通过以下步骤在 Windows XP 上使用 Aero 主题(Vista 和 Windows 7 使用):
- Add PresentationFramework.Aero to your application's references list as a requires
- Edit your App.xaml
- 根据需要将 PresentationFramework.Aero 添加到应用程序的引用列表中
- 编辑您的 App.xaml
from this
由此
<Application.Resources>
<!-- Your stuff here -->
</Application.Resources>
to this
对此
<Application.Resources>
<ResourceDictionary>
<!-- Put your stuff here instead -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Source:http://mrpmorris.blogspot.com/2008/05/using-vista-aero-theme-in-xp-wpf-apps.html
来源:http : //mrpmorris.blogspot.com/2008/05/using-vista-aero-theme-in-xp-wpf-apps.html
Other alternatives below. Be sure to add the corresponding assembly to your application's reference list as a requires.
下面的其他选择。请务必根据需要将相应的程序集添加到应用程序的参考列表中。
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Classic;component/themes/Classic.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Royale;component/themes/Royale.NormalColor.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna.Homestead;component/themes/Luna.Homestead.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna.Metallic;component/themes/Luna.Metallic.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Zune;component/themes/Zune.NormalColor.xaml"/>
回答by GuYsH
One addition to Lars' answer and DanM's update:
Lars 的回答和 DanM 的更新的一项补充:
When deploying, you must add the aero Dll to the installation dir.
部署时,必须在安装目录中添加aero Dll。
You can do it by going to the properties of PresentationFramework.Aero you added to the references and setting CopyLocal=True.
Then, you'll have to go to whatever deployment tool you're using (I love WIX...) and add it to the list of deployed files.
您可以通过转到您添加到引用和设置中的 PresentationFramework.Aero 的属性来完成CopyLocal=True。然后,您必须使用正在使用的任何部署工具(我喜欢 WIX...)并将其添加到已部署文件列表中。
回答by GuYsH
Go to your solution/project properties, and under "References" you will be able to add a reference to PresentationFramework.Aero... Apply it in your code and it should work nicely
转到您的解决方案/项目属性,在“参考”下,您将能够添加对 PresentationFramework.Aero 的引用...将其应用到您的代码中,它应该可以很好地工作
I hope my answer helps you
希望我的回答对你有帮助

