A relative n00b to WPF. I have a ListView thus:
<ListView>
<ListView.View>
<GridView>
...
</GridView>
</ListView.View>
<ListView.Resources>
<Style TargetType="{x:Type ListViewItem}">
<EventSetter Event="MouseDoubleClick" Handler="ItemDoubleClick"/>
</Style>
</ListView.Resources>
</ListView>
And in my app.xaml I have the following styles:
<Style TargetType="{x:Type ListView}">
<Setter Property="ItemContainerStyle" Value="{DynamicResource ListViewItemStyle}"/>
</Style>
<Style x:Key="ListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="Border" Padding="4">
<GridViewRowPresenter x:Name="ItemText"
TextBlock.FontSize="14" TextBlock.Foreground="{x:Static SystemColors.ControlDarkDarkBrush}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
<Condition Property="IsSelected" Value="False"/>
</MultiTrigger.Conditions>
<Setter TargetName="ItemText" Property="TextBlock.Foreground" Value="{x:Static SystemColors.WindowTextBrush}"/>
</MultiTrigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="{x:Static SystemColors.HighlightBrush}"/>
<Setter TargetName="ItemText" Property="TextBlock.Foreground" Value="{x:Static SystemColors.HighlightTextBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
But once I’m setting the ItemContainerStyle, the double-click no longer fires. If I remove it, it fires but my ListViewItems are not styled.
What am I missing here?
Your local resource is overridden by the application resources style which changes the ListView’s ItemContainerStyle property. I would suggest setting the style directly on the
ListView.ItemContainerStyleand basing the style on the existing one:(This assumes implicit styling, so either remove the key of the style in your application resources or reference it directly using that key in the
BasedOnproperty)