views:

340

answers:

1

In a WPF application I have a ListView:

<ListView Name="ItemSelList" ItemsSource="{Binding ItemColl}" SelectionChanged="ItemSelList_SelectionChanged">
   <ListView.View>
     <GridView>
      <GridViewColumn Header="Date" Width="90" DisplayMemberBinding="{Binding Date}"/>
      <GridViewColumn Header="Time" Width="90" DisplayMemberBinding="{Binding Time}"/>
      <GridViewColumn Header="Description" Width="250" DisplayMemberBinding="{Binding Description}"/>
     </GridView>
  </ListView.View>
</ListView>

When running application under Windows Vista, everything is OK. When running under Windows XP - the default font size of ListView's rows is too small and rows of the ListView don't change color when user hovers with a mouse over them.

How to do so that ListView appearance under Windows XP is the same as under Vista?

+2  A: 

This is due to WPF picking up different themes for the two operating systems. Themes are default styles based on the operating system level. Vista gets you the Aero theme while Windows XP gets you the Luna set of themes.

XP may not be capable of all the visual flashiness of the Aero theme and the Luna theme may look understated in Vista and Windows 7, but you can override the theme with a simple style. Simply define a style for your ListView that fully specifies the appearance that you want. I THINK (but am not certain) that Expression Blend has a way to extract the theme information for you.

It appears you can also override the theme that WPF would pick for you (although I haven't tried this myself).

  1. Add a reference to the assembly which contains the correct theme. For Vista (Aero), for example, this is PresentationFramework.Aero.
  2. Merge in the theme's resource dictionary from the assembly in your App.xaml. Change the Source to be the correct assembly and component name. You can generally find the correct component name by searching on the version of windows you want and "wpf theme name" or something similar. Note that this will re-theme all controls in your application!

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    

If the desire is only to retheme the one ListView, I would merge the resource dictionary in the ListView itself or an immediate parent element.

Ben Von Handorf
Thanks, it's very helpful! +1
rem