DoubleAnimation Class
Definition
Animates the value of a Double property between two target values using linear interpolation over a specified Duration.
Equivalent WinUI class: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.
public ref class DoubleAnimation sealed : Timeline
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Static(Windows.UI.Xaml.Media.Animation.IDoubleAnimationStatics, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.WebHostHidden]
class DoubleAnimation sealed : Timeline
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.WebHostHidden]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.UI.Xaml.Media.Animation.IDoubleAnimationStatics, 65536, "Windows.Foundation.UniversalApiContract")]
class DoubleAnimation sealed : Timeline
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.Xaml.Media.Animation.IDoubleAnimationStatics), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.WebHostHidden]
public sealed class DoubleAnimation : Timeline
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.WebHostHidden]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.Xaml.Media.Animation.IDoubleAnimationStatics), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class DoubleAnimation : Timeline
Public NotInheritable Class DoubleAnimation
Inherits Timeline
<DoubleAnimation />
- Inheritance
- Attributes
Windows 10 requirements
Device family |
Windows 10 (introduced in 10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (introduced in v1.0)
|
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 (@"Windows.Foundation.Point?text=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() |
Initializes a new instance of the DoubleAnimation class. Equivalent WinUI constructor: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.DoubleAnimation. |
Properties
AutoReverse |
Gets or sets a value that indicates whether the timeline plays in reverse after it completes a forward iteration. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.Timeline.AutoReverse. (Inherited from Timeline) |
BeginTime |
Gets or sets the time at which this Timeline should begin. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.Timeline.BeginTime. (Inherited from Timeline) |
By |
Gets or sets the total amount by which the animation changes its starting value. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.By. |
ByProperty |
Identifies the By dependency property. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.ByProperty. |
Dispatcher |
Gets the CoreDispatcher that this object is associated with. The CoreDispatcher represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread. Equivalent WinUI property: Microsoft.UI.Xaml.DependencyObject.Dispatcher. (Inherited from DependencyObject) |
Duration |
Gets or sets the length of time for which this timeline plays, not counting repetitions. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.Timeline.Duration. (Inherited from Timeline) |
EasingFunction |
Gets or sets the easing function applied to this animation. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.EasingFunction. |
EasingFunctionProperty |
Identifies the EasingFunction dependency property. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.EasingFunctionProperty. |
EnableDependentAnimation |
Gets or sets a value that declares whether animated properties that are considered dependent animations should be permitted to use this animation declaration. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.EnableDependentAnimation. |
EnableDependentAnimationProperty |
Identifies the EnableDependentAnimation dependency property. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.EnableDependentAnimationProperty. |
FillBehavior |
Gets or sets a value that specifies how the animation behaves after it reaches the end of its active period. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.Timeline.FillBehavior. (Inherited from Timeline) |
From |
Gets or sets the animation's starting value. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.From. |
FromProperty |
Identifies the From dependency property. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.FromProperty. |
RepeatBehavior |
Gets or sets the repeating behavior of this timeline. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.Timeline.RepeatBehavior. (Inherited from Timeline) |
SpeedRatio |
Gets or sets the rate, relative to its parent, at which time progresses for this Timeline. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.Timeline.SpeedRatio. (Inherited from Timeline) |
To |
Gets or sets the animation's ending value. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.To. |
ToProperty |
Identifies the To dependency property. Equivalent WinUI property: Microsoft.UI.Xaml.Media.Animation.DoubleAnimation.ToProperty. |
Methods
Events
Completed |
Occurs when the Storyboard object has completed playing. Equivalent WinUI event: Microsoft.UI.Xaml.Media.Animation.Timeline.Completed. (Inherited from Timeline) |