tags:

views:

369

answers:

1

I want to be notified when the animation is completed. However, when I apply the following code, I get the following error

"The event 'Completed' cannot be specified on a Target tag in a Style. Use an EventSetter instead."

<Style x:Key="CredentialEntryListViewItemStyle" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource alternatingListViewItem}">
  <Setter Property="HorizontalContentAlignment" Value="Stretch" />
  <Setter Property="VerticalContentAlignment" Value="Stretch" />
  <Style.Triggers>
    <DataTrigger Binding="{Binding IsDuplicated}" Value="True">
      <DataTrigger.EnterActions>
        <BeginStoryboard>
          <Storyboard>
            <ColorAnimation AutoReverse="True" 
                            RepeatBehavior="2x"
                            Completed="OnColorAnimationCompleted"
                            Storyboard.TargetProperty="Foreground.(SolidColorBrush.Color)" 
                            To="Orange" Duration="0:0:0.3"/>
          </Storyboard>
        </BeginStoryboard>
      </DataTrigger.EnterActions>
    </DataTrigger>
  </Style.Triggers>
</Style>
+1  A: 

I think the issue is that WPF cannot 'smartly' hook up your OnColorAnimationCompleted event on your ListViewItem because it has no way of knowing what your ListViewItem's type is, and thus it cannot subscribe OnColorAnimationCompleted to the Completed event.

Edit: Can you do whatever you need to do in the exit actions???

Scott
Thanks!The real problem I was having was that I want to force the color of the control to it original color once the animation was done. The reason being that if the if the animation was started multiple times in a short timespan, the color would not get set back to it's original color. The solution to my problem was to FillBehavior to Stop. "By setting FillBehavior to Stop, you tell the animation to stop affecting its target property after it reaches the end of its active period."Thanks for your answer, it help me understand WPF more.Cheers!
Terenced