Search code examples
wpfxaml

WPF Storyboard Animation Loops Forever Even After Being Set


I have a a custom user control to animate based on a DependencyProperty which is bound to a DataTrigger. If the DependencyProperty is equal to Failure, it should animate the fill color of a rectangle (named buttonColor) within the user control.

For some reason though, it always loops forever even if I set the RepeatBehavior to any value including 1.

If I remove the RepeatBehavior attribute, it only plays the animation once (as expected). Here is the code which I have the issue:

<DataTrigger Binding="{Binding Path=ButtonAction.Status}" Value="Failure">
    <DataTrigger.EnterActions>
        <StopStoryboard BeginStoryboardName="Pulse"/>

        <BeginStoryboard>
            <Storyboard RepeatBehavior="1">
                <ColorAnimation Storyboard.TargetName="buttonColor"
                                Storyboard.TargetProperty="Fill.Color" 
                                To="{StaticResource FailedColor}" 
                                AutoReverse="True" />
            </Storyboard>
        </BeginStoryboard>
    </DataTrigger.EnterActions>
</DataTrigger>

Solution

  • The correct syntax to repeat N times is:

    <Storyboard RepeatBehavior="Nx">
    

    for example:

    <Storyboard RepeatBehavior="6x">