A trigger action that begins a Storyboard and distributes its animations to their targeted objects and properties.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Pause, Resume, Stop, or Otherwise Control a Storyboard Interactively
To be able to pause, resume, or otherwise control a Storyboard that was declared in markup interactively, you must set the Name property of its . You can then control the Storyboard by using a ControllableStoryboardAction object (such as PauseStoryboard, ResumeStoryboard, or StopStoryboard) to control it by referencing its Name. If the Name of is unspecified, the Storyboard cannot be interactively controlled after it is begun. See How to: Use Event Triggers to Control a Storyboard After It Starts for more information.
This example shows how to use a Storyboard to animate properties. To animate a property by using a Storyboard, create an animation for each property that you want to animate and also create a Storyboard to contain the animations.
The type of property determines the type of animation to use. For example, to animate a property that takes Double values, use a DoubleAnimation. The TargetName and TargetProperty attached properties specify the object and property to which the animation is applied.
To start a storyboard in Extensible Application Markup Language (XAML), use a action and an EventTrigger. The EventTrigger begins the action when the event that is specified by its RoutedEvent property occurs. The action starts the Storyboard.
The following example uses Storyboard objects to animate two Button controls. To make the first button change in size, its Width is animated. To make the second button change color, the Color property of the SolidColorBrush is used to set the Background of the button that is animated.
<!-- StoryboardExample.xaml Uses storyboards to animate properties. --> <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowTitle="Animate Properties with Storyboards"> <Border Background="White"> <StackPanel Margin="30" HorizontalAlignment="Left" MinWidth="500"> <TextBlock>Storyboard Animation Example</TextBlock> <!-- The width of this button is animated. --> <Button Name="myWidthAnimatedButton" Height="30" Width="200" HorizontalAlignment="Left"> A Button <Button.Triggers> <!-- Animates the width of the first button from 200 to 300. --> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="myWidthAnimatedButton" Storyboard.TargetProperty="Width" From="200" To="300" Duration="0:0:3" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button> <!-- The color of the brush used to paint this button is animated. --> <Button Height="30" Width="200" HorizontalAlignment="Left">Another Button <Button.Background> <SolidColorBrush x:Name="myAnimatedBrush" Color="Blue" /> </Button.Background> <Button.Triggers> <!-- Animates the color of the brush used to paint the second button from red to blue . --> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="myAnimatedBrush" Storyboard.TargetProperty="Color" From="Red" To="Blue" Duration="0:0:7" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button> </StackPanel> </Border> </Page>
Although animations can target both a FrameworkElement object, such as a Control or Panel, and a Freezable object, such as a Brush or Transform, only framework elements have a Name property. To assign a name to a freezable so that it can be targeted by an animation, use the x:Name Attribute, as the previous example shows.
If you use code, you must create a NameScope for a FrameworkElement and register the names of the objects to animate with that FrameworkElement. To start the animations in code, use a action with an EventTrigger. Optionally, you can use an event handler and the Begin method of Storyboard. The following example shows how to use the Begin method.
If you use code, you are not limited to using Storyboard objects in order to animate properties. For more information and examples, see How to: Animate a Property Without Using a Storyboard and How to: Animate a Property by Using an AnimationClock.
|How to: Trigger an Animation When a Property Value Changes||This example shows how to use a Trigger to start a Storyboard when a property value changes. You can use a Trigger inside a Style, ControlTemplate, or DataTemplate.|
|How to: Specify HandoffBehavior Between Storyboard Animations||This example shows how to specify handoff behavior between storyboard animations. The HandoffBehavior property of specifies how new animations interact with any existing ones that are already applied to a property.|
|How to: Animate in a Style||This example shows how to animate properties within a style. When animating within a style, only the framework element for which the style is defined can be targeted directly. To target a freezable object, you must "dot down" from a property of the styled element.|
|How to: Use Event Triggers to Control a Storyboard After It Starts||This example shows how to control a Storyboard after it starts. To start a Storyboard by using XAML, use , which distributes the animations to the objects and properties they animate and then starts the storyboard. If you give a name by specifying its Name property, you make it a controllable storyboard. You can then interactively control the storyboard after it starts.|
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.