DoubleAnimation
DoubleAnimation
DoubleAnimation
DoubleAnimation
Class
Definition
public : sealed class DoubleAnimation : Timeline, IDoubleAnimationpublic sealed class DoubleAnimation : Timeline, IDoubleAnimationPublic NotInheritable Class DoubleAnimation Inherits Timeline Implements IDoubleAnimation// This API is not available in Javascript.
<DoubleAnimation />
- Inheritance
-
DoubleAnimationDoubleAnimationDoubleAnimationDoubleAnimation
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Inherited Members
Inherited properties
Inherited methods
Inherited events
Examples
The following example shows how to use DoubleAnimation to create a rectangle that fades in and out of view after it is loaded.
<StackPanel>
<StackPanel.Resources>
<Storyboard x:Name="myStoryboard">
<DoubleAnimation
Storyboard.TargetName="MyAnimatedRectangle"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:3"
AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</StackPanel.Resources>
<Rectangle Loaded="Start_Animation" x:Name="MyAnimatedRectangle"
Width="100" Height="100" Fill="Blue" />
</StackPanel>
// Start the animation when the object loads
private void Start_Animation(object sender, RoutedEventArgs e)
{
myStoryboard.Begin();
}
' Start the animation when the object loads
Private Sub Start_Animation(ByVal sender As Object, ByVal e As EventArgs)
myStoryboard.Begin()
End Sub
<Canvas>
<Canvas.Resources>
<Storyboard x:Name="myStoryboard">
<!-- Animate the TranslateTransform's X property
from 0 to 350, then 50, then 200 over 10 seconds. -->
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="MyAnimatedTranslateTransform"
Storyboard.TargetProperty="X"
Duration="0:0:10" EnableDependentAnimation="True">
<!-- Using a LinearDoubleKeyFrame, the rectangle moves
steadily from its starting position to 500 over
the first 3 seconds. -->
<LinearDoubleKeyFrame Value="500" KeyTime="0:0:3" />
<!-- Using a DiscreteDoubleKeyFrame, the rectangle suddenly
appears at 400 after the fourth second of the animation. -->
<DiscreteDoubleKeyFrame Value="400" KeyTime="0:0:4" />
<!-- Using a SplineDoubleKeyFrame, the rectangle moves
back to its starting point. The animation starts out slowly at
first and then speeds up. This KeyFrame ends after the 6th
second. -->
<SplineDoubleKeyFrame KeySpline="0.6,0.0 0.9,0.00" Value="0" KeyTime="0:0:6" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Canvas.Resources>
<Rectangle PointerPressed="Pointer_Clicked" Fill="Blue"
Width="50" Height="50">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="MyAnimatedTranslateTransform" />
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
// Start the animation when the object loads
private void Start_Animation(object sender, RoutedEventArgs e)
{
myStoryboard.Begin();
}
' Start the animation when the object loads
Private Sub Start_Animation(ByVal sender As Object, ByVal e As EventArgs)
myStoryboard.Begin()
End Sub
Remarks
Use DoubleAnimation to animate the property value of any dependency property that is of type Double.
Sometimes you'll need to use indirect property targeting in order to target a sub-property of another object that's the value of a property on the target. For example, in order to animate the X component of a RenderTransform of a UIElement, you need to reference some of the intermediate object-property values, until the last step in the indirect property path is truly a Double value, as is the case with TranslateTransform.X. The correct string to use for Storyboard.TargetProperty in this example is "(UIElement.RenderTransform).(TranslateTransform.X)". For more info on indirect property targeting and other storyboarded animation concepts, see Storyboarded animations.
A DoubleAnimation typically has at least one of the From, By or To properties set, but never all three.
- From only: The animation progresses from the value specified by the From property to the base value of the property being animated.
- From and To: The animation progresses from the value specified by the From property to the value specified by the To property.
- From and By: The animation progresses from the value specified by the From property to the value specified by the sum of the From and By properties.
- To only: The animation progresses from the animated property's base value or a previous animation's output value to the value specified by the To property.
- By only: The animation progresses from the base value of the property being animated or a previous animation's output value to the sum of that value and the value specified by the By property.
You can't animate the X and Y values of a Point using a DoubleAnimation, because these properties aren't dependency properties (Point is a structure and can't have dependency properties.) Instead, use PointAnimation to animate dependency properties that have a Point value.
You also can't use DoubleAnimation to animate int values or byte values. Instead, you'll have to use ObjectAnimationUsingKeyFrames, which won't give you an interpolation behavior, so you might need to define multiple keyframes to get a reasonably smooth animation. There aren't many UI-related dependency properties that use int values or byte values, so this shouldn't be a common scenario other than for custom properties.
The From, By or To properties of a DoubleAnimation aren't strictly a Double. Instead these are a Nullable for Double. The default value for these is null, not 0. That null value is how the animation system distinguishes that you haven't specifically set a value. Visual C++ component extensions (C++/CX) doesn't have a Nullable type, so it uses IReference instead.
Constructors
DoubleAnimation() DoubleAnimation() DoubleAnimation() DoubleAnimation()
Initializes a new instance of the DoubleAnimation class.
public : DoubleAnimation()public DoubleAnimation()Public Sub New()// This API is not available in Javascript.
Properties
By By By By
Gets or sets the total amount by which the animation changes its starting value.
public : IReference<double> By { get; set; }public Nullable<double> By { get; set; }Public ReadWrite Property By As Nullable<double>// This API is not available in Javascript.
<DoubleAnimation By="double"/>
- Value
- IReference<double> Nullable<double> Nullable<double> Nullable<double>
The total amount by which the animation changes its starting value. The default is null.
If you are programming using C# or Visual Basic, the type of this property is projected as double?(a nullable double).
ByProperty ByProperty ByProperty ByProperty
EasingFunction EasingFunction EasingFunction EasingFunction
Gets or sets the easing function applied to this animation.
public : EasingFunctionBase EasingFunction { get; set; }public EasingFunctionBase EasingFunction { get; set; }Public ReadWrite Property EasingFunction As EasingFunctionBase// This API is not available in Javascript.
<DoubleAnimation>
<DoubleAnimation.EasingFunction>
singleEasingFunction
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
The easing function applied to this animation.
Examples
This XAML example applies a BounceEase easing function to a DoubleAnimation to create a bouncing effect.
<StackPanel x:Name="LayoutRoot" Background="White">
<StackPanel.Resources>
<Storyboard x:Name="myStoryboard">
<DoubleAnimation From="30" To="200" Duration="00:00:3"
Storyboard.TargetName="ball"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)">
<DoubleAnimation.EasingFunction>
<BounceEase Bounces="4" EasingMode="EaseOut"
Bounciness="1.8" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</StackPanel.Resources>
<Ellipse x:Name="ball" MouseLeftButtonDown="Clicked"
Fill="Blue" Width="100" Height="100">
<Ellipse.RenderTransform>
<TranslateTransform/>
<Ellipse.RenderTransform>
<Ellipse
</StackPanel>
// When the user clicks the object, the animation begins.
private void Clicked(object sender, PointerRoutedEventArgs e)
{
myStoryboard.Begin();
}
Remarks
Easing functions allow you to apply custom mathematical formulas to your animations. Mathematical operations are often useful to produce animations that simulate real-world physics in a 2-D coordinate system. For example, you may want an object to realistically bounce or behave as though it were on a spring. For a list of easing functions and info on how to use them, see Key-frame animations and easing function animations.
- See Also
EasingFunctionProperty EasingFunctionProperty EasingFunctionProperty EasingFunctionProperty
Identifies the EasingFunction dependency property.
public : static DependencyProperty EasingFunctionProperty { get; }public static DependencyProperty EasingFunctionProperty { get; }Public Static ReadOnly Property EasingFunctionProperty As DependencyProperty// This API is not available in Javascript.
The identifier for the EasingFunction dependency property.
EnableDependentAnimation EnableDependentAnimation EnableDependentAnimation EnableDependentAnimation
Gets or sets a value that declares whether animated properties that are considered dependent animations should be permitted to use this animation declaration.
public : PlatForm::Boolean EnableDependentAnimation { get; set; }public bool EnableDependentAnimation { get; set; }Public ReadWrite Property EnableDependentAnimation As bool// This API is not available in Javascript.
<DoubleAnimation EnableDependentAnimation="bool" />
- Value
- PlatForm::Boolean bool bool bool
true if the animation can be used for a dependent animation case. false if the animation cannot be used for a dependent animation case. The default is false.
Remarks
What's considered a dependent animation?
Not all custom animations you create can run by default in a Windows Runtime app, if the animation system determines that the animation might cause bad performance in your UI. Animations where the system determines there could be a performance impact are called dependent animations. It's dependent because your animation is actively and frequently updating objects on the UI thread, which is also where current user input and other programmatic updates are making runtime changes to UI.
A dependent animation that's consuming extensive system resources on the UI thread can make the app appear unresponsive in certain situations. If your animation causes a layout change or otherwise has the potential to impact performance on the UI thread, you often need to explicitly enable the animation to see it run. That's what the EnableDependentAnimation property on specific animation classes is for. Use this property with caution, because setting it to true means you are deliberately acknowledging that the animation might slow down other operations on the UI thread when it runs.
For more info, see Storyboarded animations. That topic includes a list of the criteria for an independent animation. An animation is a dependent animation if it doesn't satisfy at least one of those criteria. For the specific property you intend to animate, and for the specifics of your animation, compare your intended animation to the criteria to see whether it would be considered dependent or independent by the system.
Another way to discover whether your animations are dependent is that you might receive a warning from your XAML design surface or tool after you compose that animation, and the warning indicates that you'll need to set EnableDependentAnimation to true to see your animation run.
As an app developer, you can also choose to apply an app-wide setting that always disables dependent animations, even those where EnableDependentAnimation is true. See Timeline.AllowDependentAnimations. This is useful to you as an app developer if you're consuming controls where the templates have dependent animations, and you've identified that as a performance problem, but you don't want to have to retemplate the whole control to turn those animations off.
- See Also
EnableDependentAnimationProperty EnableDependentAnimationProperty EnableDependentAnimationProperty EnableDependentAnimationProperty
Identifies the EnableDependentAnimation dependency property.
public : static DependencyProperty EnableDependentAnimationProperty { get; }public static DependencyProperty EnableDependentAnimationProperty { get; }Public Static ReadOnly Property EnableDependentAnimationProperty As DependencyProperty// This API is not available in Javascript.
The identifier for the EnableDependentAnimation dependency property.
From From From From
Gets or sets the animation's starting value.
public : IReference<double> From { get; set; }public Nullable<double> From { get; set; }Public ReadWrite Property From As Nullable<double>// This API is not available in Javascript.
<DoubleAnimation From="double"/>
- Value
- IReference<double> Nullable<double> Nullable<double> Nullable<double>
The starting value of the animation. The default is null.
If you are programming using C# or Visual Basic, the type of this property is projected as double?(a nullable double).
FromProperty FromProperty FromProperty FromProperty
Identifies the From dependency property.
public : static DependencyProperty FromProperty { get; }public static DependencyProperty FromProperty { get; }Public Static ReadOnly Property FromProperty As DependencyProperty// This API is not available in Javascript.
The identifier for the From dependency property.
To To To To
Gets or sets the animation's ending value.
public : IReference<double> To { get; set; }public Nullable<double> To { get; set; }Public ReadWrite Property To As Nullable<double>// This API is not available in Javascript.
<DoubleAnimation To="double"/>
- Value
- IReference<double> Nullable<double> Nullable<double> Nullable<double>
The ending value of the animation. The default is null.
If you are programming using C# or Visual Basic, the type of this property is projected as double?(a nullable double).