Is there any equivalent to Flash's Typewriter effects in WPF?
Thanks in advance! MemphiZ
Is there any equivalent to Flash's Typewriter effects in WPF?
Thanks in advance! MemphiZ
By typewriter effects you mean the string being displayed letter by letter?
You can achieve similar effect with StringAnimationUsingKeyframes object, however, you would have to enter every string value manually.
To create this effect automatically, you would have to write your own animation object, most likely one based on StringAnimationBase class.
OK I made it work!
private void TypewriteTextblock(string textToAnimate, TextBlock txt, TimeSpan timeSpan)
{
Storyboard story = new Storyboard();
story.FillBehavior = FillBehavior.HoldEnd;
story.RepeatBehavior = RepeatBehavior.Forever;
DiscreteStringKeyFrame discreteStringKeyFrame;
StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames();
stringAnimationUsingKeyFrames.Duration = new Duration(timeSpan);
string tmp = string.Empty;
foreach(char c in textToAnimate)
{
discreteStringKeyFrame = new DiscreteStringKeyFrame();
discreteStringKeyFrame.KeyTime = KeyTime.Paced;
tmp += c;
discreteStringKeyFrame.Value = tmp;
stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
}
Storyboard.SetTargetName(stringAnimationUsingKeyFrames, txt.Name);
Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
story.Children.Add(stringAnimationUsingKeyFrames);
story.Begin(txt);
}
But is there a way to have the characters fade in?