I want to animate the text of a textbox using StringAnimationUsingKeyFrames
and DiscreteStringKeyFrame
<TextBlock x:Name="txtStateRunning" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard x:Name="textAnimation">
<StringAnimationUsingKeyFrames Storyboard.TargetName="txtStateRunning"
Storyboard.TargetProperty="Text" RepeatBehavior="Forever" AutoReverse="False" >
<DiscreteStringKeyFrame Value="Running ." KeyTime="0:0:0" />
<DiscreteStringKeyFrame Value="Running .." KeyTime="0:0:0.5" />
<DiscreteStringKeyFrame Value="Running ..." KeyTime="0:0:1" />
<DiscreteStringKeyFrame Value="Running ...." KeyTime="0:0:1.5" />
</StringAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
In the code I have 4 * DiscreteStringKeyFrame
but actually I see only 3 * running. The DiscreteStringKeyFrame
at time 1.5 is not executed. What I am missing?
It is happening because your last frame begining to show and instantly replacing by first frame.
You can fix it by adding one more DiscreteStringKeyFrame at the end:
Or by setting
Duration
for StringAnimationUsingKeyFrames: