As the title states, I am attempting to have a ListViewItem
background change colors when the item is loaded. I am able to get the opacity to change (my very striped down XAML):
<ListView Background="Black" ItemsSource="{Binding Somesource}" Drop="AddItem">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=OneWay}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Grid x:Name="SignalGrid">
<!-- Grid Information -->
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected}" Value="false">
<Setter TargetName="SignalGrid"
Property="Background"
Value="Transparent"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsSelected}" Value="true">
<Setter TargetName="SignalGrid"
Property="Background" Value="Blue"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard AutoReverse="True"
RepeatBehavior="6x">
<DoubleAnimation Duration="0:0:0.3"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.3"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
This works fine, however is not the true feature I wamt. I tried to do the storyboard
like:
<Storyboard AutoReverse="True" RepeatBehavior="6x">
<ColorAnimation Duration="0:0:0.3"
Storyboard.TargetProperty="(ListViewItem.Background).(SolidColorBrush.Color)" To="Blue"/>
</Storyboard>
However this does nothing. I included the IsSelected
DataTriggers
because the basic idea is that I want to switch between IsSelected = true
to IsSelected = false
when the item is first added (i.e. the background toggles between blue and black). I am guessing that my issue is with Storyboard.TargetProperty="(ListViewItem.Background).(SolidColorBrush.Color)"
and I'm sure I'm missing something simple, but any help would be greatly appreciated.
EDIT I found the solution. In <!-- Grid Information -->
I have a border, so I used this solution to solve my problem.