2010-01-16 83 views
36

有什麼辦法讓WPF應用程序看起來像在Windows 7上運行,即使它運行在XP上?我正在尋找一些可以粘貼的主題。我知道Codeplex上的主題項目(http://www.codeplex.com/wpfthemes),但它缺少DataGrid的支持,這是我非常需要的。我在想也許Windows 7主題只是一個簡單的端口,或者已經存在於某個文件中。你有任何信息(即使它是壞消息),將不勝感激。Windows 7的WPF主題?

更新

使用@Lars Truijens想法,我能夠獲得Windows 7的外觀的主要控件,但遺憾的是它沒有爲WPF工具包DataGrid控制,我需要工作。

DataGrid看起來是這個Aero主題

Windows XP-look DataGrid

DataGrid應該這個樣子

Windows 7-look DataGrid

所以,我仍然在尋找一個SOLUT如果任何人有任何想法,就解決這個問題。也許有人已經構建了涵蓋WPF工具包控件的Aero主題的擴展?再次,你有任何信息非常感謝。

更新2 - 問題已解決!

要讓Aero主題與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" ...> 
+1

你的更新2拯救了我的生命! 感謝您發佈更新! – Sonosar 2013-06-16 20:40:13

回答

46

WPF配備在所有的Windows版本的標準Windows主題。例如,你可以有Aero主題(其中Vista和Windows 7中使用)在Windows XP上執行下列步驟:

  1. 添加PresentationFramework.Aero到應用程序的引用列表作爲需要
  2. 編輯您的應用程序。 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"/> 
+0

+1謝謝!我會很快嘗試這個。 – devuxer 2010-01-16 17:05:18

+0

我終於有機會嘗試一下了。它確實有效,但正如我擔心的那樣,不是用於DataGrid控件。請檢查我的更新。 'DataGrid'w/Aero主題的外觀仍然是XP。 – devuxer 2010-01-19 21:41:30

+0

好吧,我只是偶然發現了一個DataGrid問題的解決方案:''ResourceDictionary Source =「pack:// application:,,,/WPFToolkit; component/Themes/Aero.NormalColor.xaml」/>'。我也會更新我的問題。 – devuxer 2010-01-19 23:21:11

4

一個除了拉斯的答案,DanM的更新:

部署時,則必須添加航空DLL來安裝目錄。

您可以通過轉到您添加到參考文獻並設置CopyLocal=True的PresentationFramework.Aero的屬性來完成此操作。然後,你將不得不去使用你正在使用的任何部署工具(我喜歡WIX ...)並將其添加到已部署文件的列表中。

+1

我不要認爲PresentationFramework.aero需要部署。根據http://msdn.microsoft.com/en-us/library/ff462634.aspx它包含在.NET框架中。 – 2011-11-17 21:59:03

+1

如果使用完整引用,則不需要部署PresentationFramework.aero。在這裏看到我的答案:http://stackoverflow.com/questions/8175410/wpf-when-using-presentationframework-aero-do-i-need-to-set-copy-local-to-tru/8185946#8185946 – 2011-11-18 16:59:38