Thursday, January 12, 2006
Triggering Animations Programmatically in WPF/Avalon/XAML
In the past, it was possible to trigger animations in Avalon (WPF/XAML) programmatically by first finding an animation's timeline, then finding the associated storyboard clock, and then using that clock's controller to trigger the animation. Here is a typical example:
Timeline tl = this.FindName("myTimeline") as Timeline;
Clock clock = this.FindStoryboardClock(tl);
clock.ClockController.Begin();
This was a bit tricky and confusing. In the December 05 CTP build, this has changed. An animation can now be triggered relatively easily, simply by triggering a storyboard:
Storyboard s = this.FindResource("myStoryboard") as Storyboard;
s.Begin(this);
That's it! Much easier, and more intuitive. However, if you are used to the old way, you may end up searching for hours to figure out how easy it now is... ;-)
Note: This assumes that the animation is put into the resources section of the main scene/window/page. If the storyboard is located elsewhere, you'd have to reference it at that particular location.
Posted @ 7:37 PM by Egger, Markus (markus@code-magazine.com)