Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Storyboard Animation Loops Forever Even After Being Set

Tags:

wpf

xaml

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>
like image 313
AXG1010 Avatar asked Jun 10 '13 20:06

AXG1010


2 Answers

The correct syntax to repeat N times is:

<Storyboard RepeatBehavior="Nx">

for example:

<Storyboard RepeatBehavior="6x">
like image 97
Federico Berasategui Avatar answered Sep 18 '22 15:09

Federico Berasategui


Setting a duration value will also limit the repeat behavior as it takes precedence. So if you have repeat behavior set on the ColorAnimationUsingKeyFrames tag but on the storyboard you set a Duration="0:0:4" then the animation will only repeat for 4 seconds.

like image 26
jogi Avatar answered Sep 20 '22 15:09

jogi