Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Storyboarded Animation Freezes If Clicked Too Quickly

I am currently having an annoying issue with the simple XAML code below. The animation does fire correctly, and will always fire correctly if I click the button after the animation has completed. If I click quickly a few times, the animation will freeze, and the animation will never run again.

Thanks so much for the help!

<!-- Admin Login Button /-->
    <ToggleButton Name="LoginButton" IsChecked="{Binding ElementName=LoginPopup, Path=IsOpen, Mode=TwoWay}" HorizontalAlignment="Right" Margin="0,35,32.334,0" VerticalAlignment="Top" Width="97" Height="77" BorderThickness="0" Grid.Column="1" Grid.ColumnSpan="2">
        <ToggleButton.Background>
            <ImageBrush ImageSource="/Resources/Images;component/Resources/titleAboutIcon.png"/>
        </ToggleButton.Background>
        <!--  <Frame x:Name="AdminFrame" Height="77" Width="97"/> /-->
        <ToggleButton.RenderTransform>
            <ScaleTransform x:Name="Buttonscale" ScaleX="1" ScaleY="1" CenterX="0" CenterY="{Binding ElementName=LoginButton, Path=ActualHeight}" />
        </ToggleButton.RenderTransform>
        <ToggleButton.Triggers>
            <EventTrigger RoutedEvent="Button.Click">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="Buttonscale" Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="1.25" Duration="0:0:0.25" AutoReverse="True"/>
                        <DoubleAnimation Storyboard.TargetName="Buttonscale" Storyboard.TargetProperty="(ScaleTransform.ScaleY)" To="1.25" Duration="0:0:0.25" AutoReverse="True"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </ToggleButton.Triggers>
    </ToggleButton>
    <!-- Admin Login Button /-->
like image 808
Giallo Avatar asked Dec 02 '25 08:12

Giallo


1 Answers

You can add FillBehavior="Stop" to your Storyboard so it will stop and reset animated properties values instead of freezing them (HoldEnd is the default value of FillBehavior, so it won't change values back to their default).

From MSDN:

Set an animations FillBehavior property to HoldEnd when you want the animation to hold its value after it reaches the end of its active period. An animation that has reached the end of its active period that has a FillBehavior setting of HoldEnd is said to be in its fill period. When you don't want an animation to hold its value after it reaches the end of its active period, set its FillBehavior property to Stop.

https://msdn.microsoft.com/en-us/library/system.windows.media.animation.timeline.fillbehavior(v=vs.110).aspx

like image 158
nkoniishvt Avatar answered Dec 03 '25 22:12

nkoniishvt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!