Blog

Windows 8 using XAML: BeginTime Animation Property

By Ken Getz

If your storyboard contains more than one simultaneous animation, you may need to delay the start of one or more of the animations. To add this behavior,you can set the BeginTime property so that specific animations delay.

Taking the previous examples, imagine that you want the circle to move fromleft to right and back again, and on the second pass, increase the height, and later, the width of the circle as well. Although all three animations exist within the same storyboard, only one of the animations starts immediately-the other two delay for a fixed period of time.

The following markup the BeginTime property to modify the start time for specific animations within the storyboard:>/p>

<Storyboard TargetName="circle">
<DoubleAnimation
Storyboard.TargetProperty="(Canvas.Left)"From="10"
To="300"
AutoReverse="True"
RepeatBehavior="3x"
Duration="0:0:2" />
<DoubleAnimation
Storyboard.TargetProperty="Height"
EnableDependentAnimation="True"
By="100"
AutoReverse="True"
BeginTime="0:0:4"
Duration="0:0:2" />
<DoubleAnimation
Storyboard.TargetProperty="Width"
EnableDependentAnimation="True"
By="100"
AutoReverse="True"
BeginTime="0:0:6"
Duration="0:0:2" />
</Storyboard>

TIP: If you create a storyboard that contains multiple animations for a single object, you can save some typing by "factoring out" the TargetName property, and applying it to the storyboard rather than to each individual animation.

You may find it worthwhile to investigate the rest of the animation properties, as well-they all play a part in creating interesting and useful animations.

Thumbnail for 557This post is an excerpt from the online courseware for our Windows 8 Using XAML: Bindings, Shapes, and Animation course written by expert Ken Getz.



Ken Getz
Ken Getz is a featured instructor for several of our Visual Studio courses. He is a Visual Basic and Visual C# expert and has been recognized multiple times as a Microsoft MVP. Ken is a seasoned instructor, successful consultant, and the author or co-author of several best-selling books. He is a frequent speaker at technical conferences like Tech-Ed, VSLive, and DevConnections and he has written for several of the industry's most-respected publications including Visual Studio Magazine, CoDe Magazine, and MSDN Magazine.


This blog entry was originally posted February 19, 2013 by Ken Getz

Windows 8 XAML