0

I've got a Style on ListViewItem that sets the Theme property

<Style x:Key="{x:Type ListViewItem}" TargetType="{x:Type ListViewItem}">
    <Setter Property="Template" Value="{StaticResource ListViewItemTemplate}"/>
</Style>

However, in one of the cases where I'm using a ListView I want to use a DataTemplateSelector to determine which Template to use

<Style x:Key="MyListStyle" TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListView}}">
    <Setter Property="ItemTemplateSelector" Value="{StaticResource MyItemTemplateSelector}"/>
</Style>

It's applied like this

<ListView Style="{StaticResource MyListStyle}/>

However, it would appear that the Style on the item takes over and that style is applied to all the items in the ListView. I found this question which had a similar problem, however, the solution simply doesn't use the Template on the Item style at all. I need to keep that.

I've played around with the ContentTemplateSelector by restyling the ListViewItems in that ListView

<Style x:Key="MyItemStyle" BasedOn="{StaticResource {x:Type ListViewItem}}" TargetType="{x:Type ListViewItem}">
    <Setter Property="ContentTemplateSelector" Value="{StaticResource MyItemTemplateSelector}"/>
</Style>

However, the Template on the other style is used instead. If I try nulling the Template then nothing shows up at all!

<Setter Property="Template" Value="{x:Null}"/

Is there a way that I can replace the Template on the ListViewItems for a given ListView while keeping the rest of my Style?

Community
  • 1
  • 1
Boumbles
  • 2,473
  • 3
  • 24
  • 42

1 Answers1

0

I was unable to override the Template set on the ListViewItem in the ListView Style.

To get around this I replaced the Template on the ListViewItem with another ItemTemplateSelector in my base ListView Style. This selector always returns my original Template. In my ListView child Style the new ItemTemplateSelector is used.

Boumbles
  • 2,473
  • 3
  • 24
  • 42