DoubleAnimation DoubleAnimation DoubleAnimation DoubleAnimation Class

Definition

Animates the value of a Double property between two target values using linear interpolation over a specified Duration.

public : sealed class DoubleAnimation : Timeline, IDoubleAnimation
public sealed class DoubleAnimation : Timeline, IDoubleAnimation
Public NotInheritable Class DoubleAnimation Inherits Timeline Implements IDoubleAnimation
var doubleAnimation = new doubleAnimation();
<DoubleAnimation />
Inheritance
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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()
var doubleAnimation = new doubleAnimation();

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>
var nullable = doubleAnimation.by;
doubleAnimation.by = nullable;
<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

Identifies the By dependency property.

public : static DependencyProperty ByProperty { get; }
public static DependencyProperty ByProperty { get; }
Public Static ReadOnly Property ByProperty As DependencyProperty
var dependencyProperty = Windows.UI.Xaml.Media.Animation.DoubleAnimation.byProperty;
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the By dependency property.

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
var easingFunctionBase = doubleAnimation.easingFunction;
doubleAnimation.easingFunction = easingFunctionBase;
<DoubleAnimation>
  <DoubleAnimation.EasingFunction>
    singleEasingFunction
  </DoubleAnimation.EasingFunction>
</DoubleAnimation>
Value
EasingFunctionBase EasingFunctionBase EasingFunctionBase EasingFunctionBase

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
var dependencyProperty = Windows.UI.Xaml.Media.Animation.DoubleAnimation.easingFunctionProperty;

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
var bool = doubleAnimation.enableDependentAnimation;
doubleAnimation.enableDependentAnimation = bool;
<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
var dependencyProperty = Windows.UI.Xaml.Media.Animation.DoubleAnimation.enableDependentAnimationProperty;

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>
var nullable = doubleAnimation.from;
doubleAnimation.from = nullable;
<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
var dependencyProperty = Windows.UI.Xaml.Media.Animation.DoubleAnimation.fromProperty;
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

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>
var nullable = doubleAnimation.to;
doubleAnimation.to = nullable;
<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).

ToProperty ToProperty ToProperty ToProperty

Identifies the To dependency property.

public : static DependencyProperty ToProperty { get; }
public static DependencyProperty ToProperty { get; }
Public Static ReadOnly Property ToProperty As DependencyProperty
var dependencyProperty = Windows.UI.Xaml.Media.Animation.DoubleAnimation.toProperty;
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the To dependency property.

AllowDependentAnimations AllowDependentAnimations AllowDependentAnimations AllowDependentAnimations

Inherited from Timeline

AutoReverse AutoReverse AutoReverse AutoReverse

Inherited from Timeline

AutoReverseProperty AutoReverseProperty AutoReverseProperty AutoReverseProperty

Inherited from Timeline

BeginTime BeginTime BeginTime BeginTime

Inherited from Timeline

BeginTimeProperty BeginTimeProperty BeginTimeProperty BeginTimeProperty

Inherited from Timeline

Dispatcher Dispatcher Dispatcher Dispatcher

Inherited from DependencyObject

Duration Duration Duration Duration

Inherited from Timeline

DurationProperty DurationProperty DurationProperty DurationProperty

Inherited from Timeline

FillBehavior FillBehavior FillBehavior FillBehavior

Inherited from Timeline

FillBehaviorProperty FillBehaviorProperty FillBehaviorProperty FillBehaviorProperty

Inherited from Timeline

RepeatBehavior RepeatBehavior RepeatBehavior RepeatBehavior

Inherited from Timeline

RepeatBehaviorProperty RepeatBehaviorProperty RepeatBehaviorProperty RepeatBehaviorProperty

Inherited from Timeline

SpeedRatio SpeedRatio SpeedRatio SpeedRatio

Inherited from Timeline

SpeedRatioProperty SpeedRatioProperty SpeedRatioProperty SpeedRatioProperty

Inherited from Timeline

Methods

ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty)

Inherited from DependencyObject

GetAnimationBaseValue(DependencyProperty) GetAnimationBaseValue(DependencyProperty) GetAnimationBaseValue(DependencyProperty) GetAnimationBaseValue(DependencyProperty)

Inherited from DependencyObject

GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty)

Inherited from DependencyObject

ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty)

Inherited from DependencyObject

RegisterPropertyChangedCallback(DependencyProperty,DependencyPropertyChangedCallback) RegisterPropertyChangedCallback(DependencyProperty,DependencyPropertyChangedCallback) RegisterPropertyChangedCallback(DependencyProperty,DependencyPropertyChangedCallback) RegisterPropertyChangedCallback(DependencyProperty,DependencyPropertyChangedCallback)

Inherited from DependencyObject

SetValue(DependencyProperty,Object) SetValue(DependencyProperty,Object) SetValue(DependencyProperty,Object) SetValue(DependencyProperty,Object)

Inherited from DependencyObject

UnregisterPropertyChangedCallback(DependencyProperty,Int64) UnregisterPropertyChangedCallback(DependencyProperty,Int64) UnregisterPropertyChangedCallback(DependencyProperty,Int64) UnregisterPropertyChangedCallback(DependencyProperty,Int64)

Inherited from DependencyObject

Events

Completed Completed Completed Completed

Inherited from Timeline

See Also