【问题标题】:Windows 7 theme for WPF?WPF 的 Windows 7 主题?
【发布时间】:2011-01-05 18:03:00
【问题描述】:

有没有什么方法可以让 WPF 应用看起来像是在 Windows 7 上运行,即使它是在 XP 上运行的?我正在寻找可以粘贴的某种主题。我知道 Codeplex 上的主题项目 (https://archive.codeplex.com/?p=wpfthemes),但它缺乏对 DataGrid 的支持,这是我非常需要的。我在想也许 Windows 7 主题只是一个简单的移植,或者已经存在于某个文件中。


更新

使用@Lars Truijens 的想法,我能够让 Windows 7 查找主要控件,但不幸的是它不适用于我需要的 WPF Toolkit DataGrid 控件。

DataGrid 在 Aero 主题下看起来像这样

DataGrid应该看起来像这样

因此,如果有人有任何想法,我仍在寻找解决此问题的方法。也许有人构建了涵盖 WPF 工具包控件的 Aero 主题的扩展?再次感谢您提供的任何信息。


更新 2 - DataGrid 问题已解决!

要使 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>

另外,我建议关闭 DataGrid 控件中的网格线(因为它们看起来可怕):

<DataGrid GridLinesVisibility="None" ...>

【问题讨论】:

  • 你的更新 2 救了我的命!!!感谢您发布更新!

标签: .net wpf windows themes wpftoolkit


【解决方案1】:

转到您的解决方案/项目属性,在“参考”下,您将能够添加对 PresentationFramework.Aero 的参考... 将它应用到您的代码中,它应该可以很好地工作

希望我的回答对你有帮助

【讨论】:

    【解决方案2】:

    对 Lars 的回答和 DanM 的更新的补充:

    部署时,必须将aero Dll添加到安装目录。

    您可以通过转到您添加到引用中的 PresentationFramework.Aero 的属性并设置 CopyLocal=True 来做到这一点。 然后,您必须使用您正在使用的任何部署工具(我喜欢 WIX...)并将其添加到已部署文件的列表中。

    【讨论】:

    【解决方案3】:

    WPF 在所有 Windows 版本中都带有标准的 Windows 主题。例如,您可以通过以下步骤在 Windows XP 上拥有 Aero 主题(Vista 和 Windows 7 使用):

    1. 根据需要将 PresentationFramework.Aero 添加到应用程序的参考列表中
    2. 编辑您的 App.xaml

    从这里

    <Application.Resources>
      <!-- Your stuff here -->
    </Application.Resources>
    

    到这里

    <Application.Resources>
      <ResourceDictionary>
        <!-- Put your stuff here instead -->
    
        <ResourceDictionary.MergedDictionaries>
          <ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
        </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
    </Application.Resources> 
    

    来源: http://mrpmorris.blogspot.com/2008/05/using-vista-aero-theme-in-xp-wpf-apps.html

    下面的其他选择。请务必根据需要将相应的程序集添加到应用程序的参考列表中。

    <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"/>
    

    【讨论】:

    • 我终于有机会试试这个了。它确实有效,但正如我担心的那样,不适用于DataGrid 控件。请查看我的更新。 DataGrid w/ Aero 主题的外观仍然是 XP。
    • 好吧,我刚刚偶然发现了DataGrid 问题的解决方案:&lt;ResourceDictionary Source="pack://application:,,,/WPFToolkit;component/Themes/Aero.NormalColor.xaml" /&gt;。我也会更新我的问题。
    • 您应该将动态引用转换为完整引用,否则您需要部署 PresentationFramework.aero。在这里查看我的答案:stackoverflow.com/questions/8175410/…
    • 它给了我FileNotFoundException: Could not load file or assembly 'PresentationFramework.Aero
    猜你喜欢
    • 1970-01-01
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 1970-01-01
    • 2011-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多