DoubleAnimation class

Applies to Windows and Windows Phone

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

Inheritance

Object
  DependencyObject
    Timeline
      DoubleAnimation

Syntax


public sealed class DoubleAnimation : Timeline


<DoubleAnimation />

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

Members

The DoubleAnimation class has these types of members:

Constructors

The DoubleAnimation class has these constructors.

ConstructorDescription
DoubleAnimation Initializes a new instance of the DoubleAnimation class.

 

Events

The DoubleAnimation class has these events.

EventDescription
Completed Occurs when the Storyboard object has completed playing. (Inherited from Timeline)

 

Methods

The DoubleAnimation class has these methods. It also inherits methods from the Object class.

MethodDescription
ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject)
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject)
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject)
SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)

 

Properties

The DoubleAnimation class has these properties.

PropertyAccess typeDescription

AutoReverse

Read/writeGets or sets a value that indicates whether the timeline plays in reverse after it completes a forward iteration. (Inherited from Timeline)

BeginTime

Read/writeGets or sets the time at which this Timeline should begin. (Inherited from Timeline)

By

Read/writeGets or sets the total amount by which the animation changes its starting value.

ByProperty

Read-onlyIdentifies the By dependency property.

Dispatcher

Read-onlyGets the CoreDispatcher that this object is associated with. (Inherited from DependencyObject)

Duration

Read/writeGets or sets the length of time for which this timeline plays, not counting repetitions. (Inherited from Timeline)

EasingFunction

Read/writeGets or sets the easing function applied to this animation.

EasingFunctionProperty

Read-onlyIdentifies the EasingFunction dependency property.

EnableDependentAnimation

Read/writeGets or sets a value that declares whether animated properties that are considered dependent animations should be permitted to use this animation declaration.

EnableDependentAnimationProperty

Read-onlyIdentifies the EnableDependentAnimation dependency property.

FillBehavior

Read/writeGets or sets a value that specifies how the animation behaves after it reaches the end of its active period. (Inherited from Timeline)

From

Read/writeGets or sets the animation's starting value.

FromProperty

Read-onlyIdentifies the From dependency property.

RepeatBehavior

Read/writeGets or sets the repeating behavior of this timeline. (Inherited from Timeline)

SpeedRatio

Read/writeGets or sets the rate, relative to its parent, at which time progresses for this Timeline. (Inherited from Timeline)

To

Read/writeGets or sets the animation's ending value.

ToProperty

Read-onlyIdentifies the To dependency property.

 

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.

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();
}


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Media.Animation
Windows::UI::Xaml::Media::Animation [C++]

Metadata

Windows.winmd

See also

Storyboarded animations
XAML animation sample
Timeline
DoubleAnimationUsingKeyFrames
Double

 

 

Show:
© 2014 Microsoft