Matthias Shapiro

I need fewer hobbies

How to Assign ColumnHeaderContainerStyle and ColumnHeaderTemplate to a ListView Style

This is just a quick note on creating a ListView style with the appropriate GridView style and template assignments.

Normally, I’ve been creating listviews that look like this:

<ListView x:Name=”MyListView”
               ItemContainerStyle
=”{DynamicResource MyListViewItemContainerStyle}”>
   
<ListView.View>
        
<GridView ColumnHeaderContainerStyle=”{DynamicResource MyListViewHeaderStyle}”
                        
ColumnHeaderTemplate=”{DynamicResource MyGridColumnHeaderTemplate}”> 

I did this because I didn’t know exactly how to assign these styles and templates to the ListView Style. In the style, ColumnHeaderContainerStyle and ColumnHeaderTemplate are not properties of the ListView, they are properties of the GridView… which you can’t create a style for.

Instead, you can encapsulate all the information above in the following style.

<Style x:Key=”CustomListViewStyle” TargetType=”{x:Type ListView}”>
      <
Setter Property=”GridView.ColumnHeaderContainerStyle” Value=”{DynamicResource MyListViewHeaderStyle}” />
     
<Setter Property=”GridView.ColumnHeaderTemplate” Value=”{DynamicResource MyGridColumnHeaderTemplate}” />
     
<Setter Property=”ItemContainerStyle” Value=”{DynamicResource MyListViewItemContainerStyle}” />
</Style>

Problem solved.

3 Responses to How to Assign ColumnHeaderContainerStyle and ColumnHeaderTemplate to a ListView Style

  1. Wow, that’s what I was looking for, what a data!
    present here at this webpage, thanks admin of this web site.

    My page: social media management Leighton Buzzard

  2. hey there and thanks in your info ? I’ve definitely picked up something new from proper here. I did then again experience some technical issues the usage of this website, since I skilled to reload the web site many times prior to I could get it to load properly. I have been considering if your hosting is OK? Not that I’m complaining, but sluggish loading instances instances will often affect your placement in google and could injury your quality score if advertising and marketing with Adwords. Well I am including this RSS to my e-mail and can look out for a lot more of your respective intriguing content. Make sure you update this again soon..

  3. Nick

    I’ve tried your solution but only the ItemContainerStyle applied not the HeaderTemplate!

    I would appreciate any help you can give me!

    — Window XAML —

    — ResourceDictionary —