The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
2 out of 2 rated this helpful - Rate this topic

How to: Use Templates to Style a ListView That Uses GridView

This example shows how to use the DataTemplate and Style objects to specify the appearance of a ListView control that uses a GridView view mode.


The following examples show Style and DataTemplate objects that customize the appearance of a column header for a GridViewColumn.

<Style x:Key="myHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
  <Setter Property="Background" Value="LightBlue"/>

<DataTemplate x:Key="myHeaderTemplate">
    <TextBlock FontSize="16" Foreground="DarkBlue">

The following example shows how to use these Style and DataTemplate objects to set the HeaderContainerStyle and HeaderTemplate properties of a GridViewColumn. The DisplayMemberBinding property defines the content of the column cells.

<GridViewColumn Header="Month" Width="80"
      HeaderContainerStyle="{StaticResource myHeaderStyle}"
      HeaderTemplate="{StaticResource myHeaderTemplate}"
      DisplayMemberBinding="{Binding Path=Month}"/>

The HeaderContainerStyle and HeaderTemplate are only two of several properties that you can use to customize column header appearance for a GridView control. For more information, see GridView Column Header Styles and Templates Overview.

The following example shows how to define a DataTemplate that customizes the appearance of the cells in a GridViewColumn.

<DataTemplate x:Key="myCellTemplateMonth">
    <TextBlock Foreground="DarkBlue" HorizontalAlignment="Center">
        <Binding Path="Month"/>

The following example shows how to use this DataTemplate to define the content of a GridViewColumn cell. This template is used instead of the DisplayMemberBinding property that is shown in the previous GridViewColumn example.

<GridViewColumn Header="Month" Width="80"
      CellTemplate="{StaticResource myCellTemplateMonth}"/>

For the complete sample, see ListView That Uses a GridView with Templates Sample.

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.