简体   繁体   English

WPF 的 Windows 7 主题?

[英]Windows 7 theme for WPF?

Is there any way to make a WPF app look like it's running on Windows 7 even if it's running on XP?有没有办法让 WPF 应用程序看起来像在 Windows 7 上运行,即使它在 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.我正在寻找某种我可以粘贴的主题。我知道 Codeplex ( https://archive.codeplex.com/?p=wpfthemes ) 上的主题项目,但它缺乏对DataGrid支持,其中是我非常需要的东西。 I was thinking maybe the Windows 7 theme would just be an easy port, or exists in some file somewhere already.我在想 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 DataGrid control, which I need.使用@Lars Truijens 的想法,我能够在 Windows 7 中查找主要控件,但不幸的是它不适用于我需要的 WPF Toolkit DataGrid控件。

DataGrid looks like this with Aero theme带有 Aero 主题的DataGrid看起来像这样

Windows XP 风格的 DataGrid

DataGrid should look like this DataGrid应该是这样的

Windows 7 外观数据网格

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?也许有人已经构建了涵盖 WPF 工具包控件的 Aero 主题扩展? Again, any information you have is much appreciated.同样,非常感谢您拥有的任何信息。


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 DataGrid controls (because they look horrible ):另外,我建议关闭DataGrid控件中的网格线(因为它们看起来很糟糕):

<DataGrid GridLinesVisibility="None" ...>

WPF comes with the standard Windows themes on all Windows versions. WPF 在所有 Windows 版本上都带有标准的 Windows 主题。 For example, you can have the Aero theme (which Vista and Windows 7 use) on Windows XP with the following steps:例如,您可以通过以下步骤在 Windows XP 上使用 Aero 主题(Vista 和 Windows 7 使用):

  1. Add PresentationFramework.Aero to your application's references list as a requires根据需要将 PresentationFramework.Aero 添加到应用程序的引用列表中
  2. Edit your App.xaml编辑您的 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"/>

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 .您可以通过转到添加到引用中的 PresentationFramework.Aero 的属性并设置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.然后,您必须使用正在使用的任何部署工具(我喜欢 WIX...)并将其添加到已部署文件列表中。

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希望我的回答对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM