HandoffBehavior Enumeration
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
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. To create this effect, the example uses two event triggers, each one having a corresponding storyboard.
Both buttons use a BeginStoryboard object and set its HandoffBehavior property. The example sets one event trigger to Compose, which causes new and existing animations to combine together by appending the new animations to the end of the composition chain. The example sets the other event trigger with the default HandoffBehavior value of SnapshotAndReplace, which causes the new animation to immediately replace the existing one.
<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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.