StringAnimationUsingKeyFrames Class
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
A key frame animation's target values are defined by its KeyFrames property, which contains a collection of StringKeyFrame objects. Each StringKeyFrame defines a segment of the animation with its own target Value and KeyTime. When the animation runs, it progresses from one key value to the next at the specified key times.
This example shows how to animate a string, which in this example is the Content property of a Button control, by using key frames.
The following example uses the StringAnimationUsingKeyFrames class to animate the Content property of a Button.
All the key frames in this example use an instance of the DiscreteStringKeyFrame class because a string animation that is created with key frames can only use discrete key frames. Discrete key frames like DiscreteStringKeyFrame create sudden jumps between values, that is, changes to the animation occur quickly and are not subtle.
<!-- Demonstrates the StringAnimationUsingKeyFrames class. A StringAnimationUsingKeyFrames is used to animate the TextContent property of a Text element. --> <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="Microsoft.Samples.KeyFrameExamples.StringAnimationUsingKeyFramesExample" Name="myRootElement" WindowTitle="StringAnimationUsingKeyFrames Example"> <StackPanel HorizontalAlignment="Center"> <Button Name="myAnimatedButton" Margin="200" FontSize="16pt" FontFamily="Verdana">Some Text <Button.Triggers> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard> <StringAnimationUsingKeyFrames Storyboard.TargetName="myAnimatedButton" Storyboard.TargetProperty="(Button.Content)" Duration="0:0:8" FillBehavior="HoldEnd"> <!-- All the key frames below are DiscreteStringKeyFrames. Discrete key frames create sudden "jumps" between values (no interpolation). Only discrete key frames can be used for String key frame animations. --> <DiscreteStringKeyFrame Value="" KeyTime="0:0:0" /> <DiscreteStringKeyFrame Value="A" KeyTime="0:0:1" /> <DiscreteStringKeyFrame Value="An" KeyTime="0:0:1.5" /> <DiscreteStringKeyFrame Value="Ani" KeyTime="0:0:2" /> <DiscreteStringKeyFrame Value="Anim" KeyTime="0:0:2.5" /> <DiscreteStringKeyFrame Value="Anima" KeyTime="0:0:3" /> <DiscreteStringKeyFrame Value="Animat" KeyTime="0:0:3.5" /> <DiscreteStringKeyFrame Value="Animate" KeyTime="0:0:4" /> <DiscreteStringKeyFrame Value="Animated" KeyTime="0:0:4.5" /> <DiscreteStringKeyFrame Value="Animated " KeyTime="0:0:5" /> <DiscreteStringKeyFrame Value="Animated T" KeyTime="0:0:5.5" /> <DiscreteStringKeyFrame Value="Animated Te" KeyTime="0:0:6" /> <DiscreteStringKeyFrame Value="Animated Tex" KeyTime="0:0:6.5" /> <DiscreteStringKeyFrame Value="Animated Text" KeyTime="0:0:7" /> </StringAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button> </StackPanel> </Page>
For the complete sample, see KeyFrame Animation Sample.
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Freezable
System.Windows.Media.Animation.Animatable
System.Windows.Media.Animation.Timeline
System.Windows.Media.Animation.AnimationTimeline
System.Windows.Media.Animation.StringAnimationBase
System.Windows.Media.Animation.StringAnimationUsingKeyFrames
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.