This appendix summarizes triggers and animations. For more detailed information, see Chapter 14.
You can place
EventTriggers inside a control's Triggers section to take action when an event occurs. Inside the
EventTrigger, you can place actions that should occur when the event takes place.
The most useful of these actions include:
PauseStoryboard — Pauses a Storyboard.
ResumeStoryboard — Resumes a paused Storyboard.
SeekStoryboard — Moves the Storyboard to a specific position in its timeline.
StopStoryboard — Stops a Storyboard. This resets properties to their original values.
RemoveStoryboard — Stops a Storyboard and frees its resources.
The following code gives a
EventTrigger. When the
Button raises its
Click event, the
EventTrigger starts a Storyboard that changes the
Canvas.Left property to 300 over a period of 0.5 seconds. The animation's
AutoReverse property is
True, so after the animation completes, it changes the
Canvas.Left property back to its original value.
<Button Name="btnClickMe" Canvas.Left="10" Canvas.Top="10" Content="Click Me"> <Button.Triggers>
<EventTrigger RoutedEvent="Button.Click"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <DoubleAnimation Duration="0:0:0.5" To="300" Storyboard.TargetProperty="(Canvas.Left)" AutoReverse="True"/> ...