I’d like to provide you with a SilverBullet™, a small snippet of Silverlight, a class or namespace hidden in the silverlight .NET framework, to help you out in times of need. It’s not to learn, but something to keep in your pocket. Just remember it’s there and you’re safe.
There are situations when you would like to start an animation as soon as your application is loaded. The EventTrigger class is what you need in that case. You may know this class from WPF, but the Silverlight version is very limited. The nice thing about this class is that it can be used in xaml, so you don’t have to do anything in codebehind.
The EventTrigger class has a couple of uninteresting properties and methods inherited from DependencyObject. The class has only 1 property you would actually use directly when defining it in Xaml: RoutedEvent. This is the event that will trigger the animation. At this point, only the Loaded event is supported. But often this is what you need anyway.
The animation you want to start is placed inside the EventTrigger element and inside a BeginStoryBoard element. The EventTrigger can contain multiple BeginStoryBoards. Each BeginStoryBoard can contain only one storyboard.
Here’s a very simple example of an animation being played when the application is loaded:
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<EasingDoubleKeyFrame KeyTime="00:00:02" Value="300"/>
<Grid x:Name="LayoutRoot" Background="White">
<Ellipse x:Name="ellipse" Fill="#FFFF0000" Stroke="#FF000000"
Tags van Technorati: Silverlight