In one of my projects, I inherited a ListView and redefined the style by installing a new control pattern. I also redefined the column heading style. So far I have found two ways to do this:
1) By setting the style key and referring to the style in the GridView:
<Style TargetType="{x:Type GridViewColumnHeader}" x:Key="MyHeaderStyle"> <Setter Property="Background" Value="Wheat" /> </Style> <GridView ColumnHeaderContainerStyle="{StaticResource MyHeaderStyle}">
2) Without setting the style key for the above style. Now I do not need to reference the style in the GridView, but it also overrides ALL list headers in my application, regardless of the type of list.
Since I use many lists in my application, I would like to do this in a third and more flexible way; setting the GridView.ColumnHeaderContainerStyle from the ListView style. This way, I will not need to refer to the header style in each GridView. Here is a simplified version of XAML:
<Window.Resources> <Style TargetType="{x:Type GridViewColumnHeader}" x:Key="MyHeaderStyle"> <Setter Property="Background" Value="Wheat" /> </Style> <Style TargetType="{x:Type list:MyListView}"> <Setter Property="GridView.ColumnHeaderContainerStyle" Value="{StaticResource MyHeaderStyle}" /> <Setter Property="Background" Value="Linen" /> </Style> </Window.Resources> <list:MyListView> <list:MyListView.View> <GridView> <GridViewColumn Header="Column1" /> <GridViewColumn Header="Column2" /> </GridView> </list:MyListView.View> </list:MyListView>
This, unfortunately, does not set the header style ... If I made this change in the XAML above, it works:
<GridView ColumnHeaderContainerStyle="{StaticResource MyHeaderStyle}">
Any ideas?
source share