Given my animation scene1. How can I pause it using a button named “Skip” using C# code behind, and play another animation scene2 after.
<Window.Resources>
<Storyboard x:Key="scene1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="whitebox">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.7" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="charName">
<DiscreteStringKeyFrame KeyTime="0:0:2" Value="Teacher"/>
<DiscreteStringKeyFrame KeyTime="0:0:7.8" Value="Teacher"/>
<DiscreteStringKeyFrame KeyTime="0:0:8" Value="Teacher"/>
</StringAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="charName">
<DiscreteObjectKeyFrame KeyTime="0:0:2" Value="{x:Static HorizontalAlignment.Left}"/>
<DiscreteObjectKeyFrame KeyTime="0:0:7.8" Value="{x:Static HorizontalAlignment.Left}"/>
<DiscreteObjectKeyFrame KeyTime="0:0:8" Value="{x:Static HorizontalAlignment.Left}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
(too long… etc.)
In addition to Jeric Paul Calderon’s answer, there’s also pause function :
storyBoard.Pause()The main thing is that
Pause()pauses the annimation at the current playback position, andStop()does stop and returns to the starting point.