The WPF Designer Guide To Styling the (your-favorite-adjectival-swear-word-here) ListView
So, after months of delay I finally figured that there are probably some people out there who want to figure out how to make the WPF listview look the way they want it to look.
A quick note: I will be dealing almost entirely with the listview look. If you want the listview to do something (functionality) or look a certain way and you can’t find the answer here, leave a comment with your suggestion and I’ll try to blog about it and place a link to the answer in my listview FAQ.
My goal is to create a significant repository on getting the stinking listview to look the way you want and do what you want it to do.
You’re probably here because, compared with most of the WPF controls, Blend gives very little guidance on how to deal with the listview (even though you use the listview for practically everything you do). So we’re going to start with the basic structure of the listview. This is what the basic listview looks like in the XAML.
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Header=”Column Header“/>
</GridView>
</ListView.View>
</ListView>
So this post will start out giving basic guidance on what to edit when you’re trying to edit the various parts of the listview. I will update these sections with links and tutorials on listview specific tasks as time goes on.
As a point of note, I recommend using an ItemSource for your listview when you’re learning ot style it. Manually putting ListViewItems into it and trying to style them will muddy the waters of good design. If you need a good ItemsSource, I recommend any of the New York Times RSS feeds.
How to connect the New York Times RSS feed to your listview
Question 1: “How do I make the items (see picture below) look the way I want them to?”

Answer: Use the ItemContainerStyle property in the ListView (and the associated ControlTemplate)
More on ItemContainerStyle and Blend
In the XAML:
Put this in the resources:
<Style x:Key=”MyItemContainerStyle” TargetType=”{x:Type ListViewItem}“>
</Style>
Put this in the composition:
<ListView ItemContainerStyle=”{DynamicResource MyItemContainerStyle}“>
Question 2: “How do I make all the items in a certain column (see below) look a certain way?”

Answer: Use a CellTemplate in the GridViewColumn
More on CellTemplate and Blend.
In the XAML:
Put this in the resources:
<DataTemplate x:Key=”MyCellTemplate” >
</DataTemplate>
Put this in the composition:
<GridViewColumn CellTemplate=”{DynamicResource MyCellTemplate}“>
Question 3: “How do I make the whole header (see below) look the way I want?”

Answer: Use the ColumnHeaderContainerStyle in the GridView (and the associated ControlTemplate)
More on the ColumnHeaderContainerStyle and Blend
In the XAML:
Put this in the resources:
<Style x:Key=”MyColumnHeaderContainerStyle” TargetType=”{x:Type GridViewColumnHeader}“>
</Style>
Put this in the composition:
<GridView ColumnHeaderContainerStyle=”{DynamicResource MyColumnHeaderContainerStyle}“>
Question 4: “How do I change the layout of the header sections (all of them)?”

Answer: Use a ColumnHeaderTemplate in the GridView
How do I get to the ColumnHeaderTemplate using Blend? (coming soon)
In the XAML:
Put this in the resources:
<DataTemplate x:Key=”MyColumnHeaderTemplate” >
</DataTemplate>
Put this in the composition:
<GridView ColumnHeaderTemplate=”{DynamicResource MyColumnHeaderTemplate}“>
Question 5: “How do I make a specific part of the header look different than another part?”
or “How do I make the red part look different than the blue part?”

Answer: Use the HeaderTemplate in the GridViewColumn
How do I get to the HeaderTemplate using Blend? (coming soon)
In the XAML:
Put this in the resources:
<DataTemplate x:Key=”MyHeaderTemplate“>
</DataTemplate>
Put this in the composition:
<GridViewColumn HeaderTemplate=”{DynamicResource MyHeaderTemplate}“>
reno:
Nice info thanks!
11 December 2007, 6:02 amjason:
Is there an easy way to get gridlines just between the columns of the ListView? Or does one have to put a Border element inside each cell and remove all item padding? (Does that even work?)
11 December 2007, 10:23 ampetem:
This is very useful - thanks a lot!
11 December 2007, 12:36 pmadmin:
Re: jason
Here is a post that can help you with grid lines. It’s kind of a hack, but I haven’t seen a better way.
11 December 2007, 2:10 pmAli Adams:
Salam Matthias,
Is there an easy way to set and get cell items by row and col indexes?
This onion-like concentric visual layers of this ****ing listview are really getting to me and currently can’t add a new item and access it immediately until the StateChanged event is fired in order to get a valid ContentPresenter etc.
Please help!
Ali Adams
7 January 2008, 11:07 amEarth, Water, Air, Fire, Light, Soul, Spirit
TheGoodDay:
Very helpful.
Do you know of how to style the seperator lines between cells in the header?
What about the vertical and horizontal scroll bars?
Minor typo. GridViewColumn has no “MyCellTemplate”. It has “CellTemplate”.
10 January 2008, 3:04 pmChe' Clark:
I have tried to implement the selected item style shown in the tutorial but it seems to apply the gradient to the entire background. If a black and white gradient is used and you select a row on top it might be white, then select a row on bottom and it will be black. I need to have the row itself show the entire gradient just like in the above examples. Am I missing something? Maybe an working example of the above gridview styling might help.
11 January 2008, 10:45 amMatthias:
TheGoodDay…
Here’s a post on styling the seperator lines (Blend calls them “Header Grippers”).
I’ll get to the ScrollBars post in the next couple weeks.
23 January 2008, 11:17 amMatthias:
Che’ Clark…
Here’s a post that goes into more detail on the Item Styling.
23 January 2008, 11:18 amDesigner WPF » Blog Archive » Embedded ListView Columns (Columns Within Columns):
[...] If you’re looking for more general information on styling the wpf listview, check out this post. It is probably much closer to what you’re looking [...]
18 April 2008, 8:15 pmDesigner WPF » Blog Archive » Styling the ScrollViewer:
[...] so. I’m going to go ahead and put up the basics here, much like my Styling the ComboBox and Styling the ListView [...]
7 August 2008, 3:51 pmJerry:
Hi,
Using Visual Studio 2008, I just added one of the pre-made templates and then went behind the code and customized it.
22 September 2008, 11:36 am