Skip to content

Latest commit

 

History

History
64 lines (37 loc) · 5.82 KB

doubleanimation.md

File metadata and controls

64 lines (37 loc) · 5.82 KB
-api-id -api-type
T:Windows.UI.Xaml.Media.Animation.DoubleAnimation
winrt class

Windows.UI.Xaml.Media.Animation.DoubleAnimation

-description

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

-xaml-syntax

<DoubleAnimation />

-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.

[!code-xamlDoubleanimation]

[!code-csharpDoubleanimation_cs]

[!code-vbDoubleanimation_cs]

[!code-xamlDoubleanimation]

[!code-csharpDoubleanimation]

[!code-vbDoubleanimation]

-see-also

Storyboarded animations, XAML animation sample, Timeline, DoubleAnimationUsingKeyFrames, Double md), Double