簡體   English   中英

WPF 的 Windows 7 主題?

[英]Windows 7 theme for WPF?

有沒有辦法讓 WPF 應用程序看起來像在 Windows 7 上運行,即使它在 XP 上運行? 我正在尋找某種我可以粘貼的主題。我知道 Codeplex ( https://archive.codeplex.com/?p=wpfthemes ) 上的主題項目,但它缺乏對DataGrid支持,其中是我非常需要的東西。 我在想 Windows 7 主題可能只是一個簡單的端口,或者已經存在於某個文件中。


更新

使用@Lars Truijens 的想法,我能夠在 Windows 7 中查找主要控件,但不幸的是它不適用於我需要的 WPF Toolkit DataGrid控件。

帶有 Aero 主題的DataGrid看起來像這樣

Windows XP 風格的 DataGrid

DataGrid應該是這樣的

Windows 7 外觀數據網格

因此,如果有人有任何想法,我仍在尋找解決此問題的方法。 也許有人已經構建了涵蓋 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" ...>

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

Lars 的回答和 DanM 的更新的一項補充:

部署時,必須在安裝目錄中添加aero Dll。

您可以通過轉到添加到引用中的 PresentationFramework.Aero 的屬性並設置CopyLocal=True 然后,您必須使用正在使用的任何部署工具(我喜歡 WIX...)並將其添加到已部署文件列表中。

轉到您的解決方案/項目屬性,在“參考”下,您將能夠添加對 PresentationFramework.Aero 的引用...將其應用到您的代碼中,它應該可以很好地工作

希望我的回答對你有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM