This is my WPF ListView which works fine.
<Window.Resources>
<Style x:Key="ItemContStyle" TargetType="{x:Type ListViewItem}">
<Style.Resources>
<SolidColorBrush x:Key="Key1" Color="#f7fcfe" />
<SolidColorBrush x:Key="Key2" Color="#fff1cf" />
<SolidColorBrush x:Key="Key3" Color="#fdeff2" />
</Style.Resources>
</Style></Window.Resources>
<ListView
Name="UserLst" Width="320"
ItemContainerStyle="{StaticResource ItemContStyle}">
<ListView.View>
<GridView>
<GridView.ColumnHeaderContainerStyle>
<Style>
<Setter Property="UIElement.Visibility" Value="Collapsed" />
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn Header="id" Width="100" DisplayMemberBinding="{Binding Path=_id}"/>
<GridViewColumn Header="UserID" Width="200" DisplayMemberBinding="{Binding Path=_UserID}"/>
</GridView>
</ListView.View>
Now I'm trying to add a function which detects left clicks on selected item as follows:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewItem_PreviewMouseLeftButtonDown" />
</Style></ListView.ItemContainerStyle>
I can't add this because there's already
ItemContainerStyle="{StaticResource ItemContStyle}"
in the ListView code. I've been wondering if someone shed some light for me!
You can use BasedOn to inherit from above style:
<ListView Name="UserLst" Width="320">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem" BasedOn="{StaticResource ItemContStyle}">
<EventSetter Event="PreviewMouseLeftButtonDown"
Handler="ListViewItem_PreviewMouseLeftButtonDown" />
</Style>
</ListView.ItemContainerStyle>
......
</ListView>
This way you will get setters, triggers from above style and you can provide your own as well specific to your ListView. (like EventSetter in your case)