42

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.


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.

DataGrid looks like this with Aero theme

Windows XP-look DataGrid

DataGrid should look like this

Windows 7-look 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.


Update 2 - DataGrid Problem solved!

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.

<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 GridLinesVisibility="None" ...>
Cœur
  • 37,241
  • 25
  • 195
  • 267
devuxer
  • 41,681
  • 47
  • 180
  • 292

3 Answers3

56

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:

  1. Add PresentationFramework.Aero to your application's references list as a requires
  2. Edit your 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

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"/>
Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
  • I finally got a chance to try this out. It does work, but as I feared, not for the `DataGrid` control. Please check out my update. The look of the `DataGrid` w/ Aero theme is still XP. – devuxer Jan 19 '10 at 21:41
  • Well sweet, I just stumbled upon a solution to the `DataGrid` problem: ``. I'll update my question as well. – devuxer Jan 19 '10 at 23:21
  • 3
    You should convert the dynamic reference into a full reference or else you need to deploy PresentationFramework.aero. See my answer here: http://stackoverflow.com/questions/8175410/wpf-when-using-presentationframework-aero-do-i-need-to-set-copy-local-to-tru/8185946#8185946 – Helge Klein Nov 18 '11 at 17:01
  • it gives me `FileNotFoundException: Could not load file or assembly 'PresentationFramework.Aero` – mrid Jan 21 '19 at 12:40
4

One addition to Lars' answer and DanM's update:

When deploying, you must add the aero Dll to the installation dir.

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.

GuYsH
  • 293
  • 1
  • 3
  • 9
  • 1
    I do not think PresentationFramework.aero needs to be deployed. According to http://msdn.microsoft.com/en-us/library/ff462634.aspx it is included in the .NET framework. – Helge Klein Nov 17 '11 at 21:59
  • 1
    PresentationFramework.aero does not need to be deployed if a full reference is used. See my answer here: http://stackoverflow.com/questions/8175410/wpf-when-using-presentationframework-aero-do-i-need-to-set-copy-local-to-tru/8185946#8185946 – Helge Klein Nov 18 '11 at 16:59
0

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

I hope my answer helps you