Inheriting the Style of an ItemContainerStyle in a WPF ListView

To allow the correct order of the tabs using the controls displayed through the ListView, I added this to the top of my ListView control:

<ListView.ItemContainerStyle> <Style> <Setter Property="KeyboardNavigation.IsTabStop" Value="False" /> </Style> </ListView.ItemContainerStyle> 

Which is great for tabs, but also violates the mouseover style of the list in question.

I tried to return it, inheriting the default value:

 <ListView.ItemContainerStyle BasedOn="{StaticResource {x:Type ItemContainerStyle}}"> <Style> <Setter Property="KeyboardNavigation.IsTabStop" Value="False" /> </Style> </ListView.ItemContainerStyle> 

What causes the assembly to break with the message "cannot set properties on property elements."

So I tried to change the garbage style for the element so that it matches what was in the stylesheet:

 <ListView.ItemContainerStyle> <Style> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="#90C8E0" /> </Trigger> </Style.Triggers> <Setter Property="KeyboardNavigation.IsTabStop" Value="False" /> </Style> </ListView.ItemContainerStyle> 

And this will not compile, complaining that IsMouseOver and Background are not recognized as properties for ItemContainter.

So I tried to create a style for it in my stylesheet and gave it a key:

 <Style x:Key="TabbedListItem" BasedOn="{StaticResource {x:Type ListViewItem}}"> <Setter Property="KeyboardNavigation.IsTabStop" Value="False" /> </Style> <ListView.ItemContainerStyle> <Style BasedOn="{StaticResource TabbedListItem}" /> </ListView.ItemContainerStyle> 

That compiles, but will not display, throwing an error "Provide a value in" System.Windows.StaticResourceExtension "throws an exception".

I have no ideas. What am I doing wrong?

+1
source share

All Articles