HandoffBehavior Enumeration
Specifies how new animations interact with any existing ones that are already applied to a property.
Assembly: PresentationCore (in PresentationCore.dll)
When you apply a Storyboard, AnimationTimeline, or AnimationClock to a property by using HandoffBehavior::Compose, any Clock objects previously associated with that property continue to consume system resources; the timing system will not remove the clocks automatically.
To avoid performance issues when you apply a large number of clocks using HandoffBehavior::Compose, you should remove composing clocks from the animated property after they complete. There are several ways to remove a clock:
To remove all clocks from a property, use the ApplyAnimationClock(DependencyProperty, AnimationClock) or BeginAnimation(DependencyProperty, AnimationTimeline) method of the animated object. Specify the property being animated as the first parameter, and nullptr as the second. This will remove all animation clocks from the property.
To remove a specific AnimationClock from a list of clocks, use the Controller property of the AnimationClock to retrieve a ClockController, then call the Remove method of the ClockController. This is typically done in the Completed event handler for a clock. Note that only root clocks can be controlled by a ClockController; the Controller property of a child clock returns nullptr. Note also that the Completed event will not be raised if the effective duration of the clock is forever. In that case, the user must determine when to call Remove.
This is primarily an issue for animations on objects that have a long lifetime. When an object is garbage collected, its clocks will also be disconnected and garbage collected.
For more information about clock objects, see Animation and Timing System Overview.
This example shows how to specify handoff behavior between storyboard animations. The HandoffBehavior property of BeginStoryboard specifies how new animations interact with any existing ones that are already applied to a property.
The following example creates two buttons that enlarge when the mouse cursor moves over them and become smaller when the cursor moves away. If you mouse over a button and then quickly remove the cursor, the second animation will be applied before the first one is finished. It is when two animations overlap like this that you can see the difference between the HandoffBehavior values of Compose and SnapshotAndReplace. A value of Compose combines the overlapping animations causing a smoother transition between animations while a value of SnapshotAndReplace causes the new animation to immediately replace the earlier overlapping animation.
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Resources> <!-- This Style specifies mouseover and mouseout behaviors. The button gets larger when the cursor moves over it and smaller when the cursor moves away. Note that the same Properties (ScaleX and ScaleY) are being targeted by both animations. The BeginStoryboard for each animation uses a HandoffBehavior of "Compose" which causes the old animation to interpolate more gradually into the new one. --> <Style x:Key="ButtonWithCompose" TargetType="{x:Type Button}"> <Setter Property="Button.RenderTransform"> <Setter.Value> <ScaleTransform CenterX="50" CenterY="50" ScaleX="1" ScaleY="1" /> </Setter.Value> </Setter> <Style.Triggers> <EventTrigger RoutedEvent="Mouse.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard > <Storyboard> <DoubleAnimation Duration="0:0:2" Storyboard.TargetProperty="RenderTransform.ScaleX" To="3" /> <DoubleAnimation Duration="0:0:2" Storyboard.TargetProperty="RenderTransform.ScaleY" To="3" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseLeave"> <EventTrigger.Actions> <BeginStoryboard HandoffBehavior="Compose"> <Storyboard> <DoubleAnimation Duration="0:0:2" Storyboard.TargetProperty="RenderTransform.ScaleX" /> <DoubleAnimation Duration="0:0:2" Storyboard.TargetProperty="RenderTransform.ScaleY" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </Style.Triggers> </Style> <!-- For this button style, BeginStoryboard uses the default HandoffBehavior of "SnapShotAndReplace" --> <Style x:Key="ButtonWithSnapShotAndReplace" TargetType="{x:Type Button}"> <Setter Property="Button.RenderTransform"> <Setter.Value> <ScaleTransform CenterX="50" CenterY="50" ScaleX="1" ScaleY="1" /> </Setter.Value> </Setter> <Style.Triggers> <EventTrigger RoutedEvent="Mouse.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard > <Storyboard> <DoubleAnimation Duration="0:0:2" Storyboard.TargetProperty="RenderTransform.ScaleX" To="3" /> <DoubleAnimation Duration="0:0:2" Storyboard.TargetProperty="RenderTransform.ScaleY" To="3" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseLeave"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <DoubleAnimation Duration="0:0:2" Storyboard.TargetProperty="RenderTransform.ScaleX" /> <DoubleAnimation Duration="0:0:2" Storyboard.TargetProperty="RenderTransform.ScaleY" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </Style.Triggers> </Style> </Page.Resources> <Canvas> <Button Style="{StaticResource ButtonWithSnapShotAndReplace}" Canvas.Top="200" Canvas.Left="200" Width="100" Height="100"> SnapShotAndReplace </Button> <Button Style="{StaticResource ButtonWithCompose}" Canvas.Top="200" Canvas.Left="400" Width="100" Height="100"> Compose </Button> </Canvas> </Page>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.