Share via


CompositionObject.StartAnimation Method

Definition

Overloads

StartAnimation(String, CompositionAnimation)

Connects an animation with the specified property of the object and starts the animation.

StartAnimation(String, CompositionAnimation, AnimationController)

Connects an animation with the specified property of the object and starts the animation.

StartAnimation(String, CompositionAnimation)

Connects an animation with the specified property of the object and starts the animation.

public:
 virtual void StartAnimation(Platform::String ^ propertyName, CompositionAnimation ^ animation) = StartAnimation;
void StartAnimation(winrt::hstring const& propertyName, CompositionAnimation const& animation);
public void StartAnimation(string propertyName, CompositionAnimation animation);
function startAnimation(propertyName, animation)
Public Sub StartAnimation (propertyName As String, animation As CompositionAnimation)

Parameters

propertyName
String

Platform::String

winrt::hstring

The property to associate the animation with.

animation
CompositionAnimation

The animation to associate with the specified property.

Windows requirements

Device family
Windows 10 (introduced in 10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v2.0)

Examples

void AnimatingVisualOffset(Visual targetVisual) 
{ 
    var animation = _compositor.CreateVector3KeyFrameAnimation(); 

    // 
    // Define specific easing functions. 
    // 


    var linear = _compositor.CreateLinearEasingFunction(); 

    var easeIn = _compositor.CreateCubicBezierEasingFunction( 
            new Vector2(0.5f, 0.0f), new Vector2(1.0f, 1.0f)); 

    var easeOut = _compositor.CreateCubicBezierEasingFunction( 
            new Vector2(0.0f, 0.0f), new Vector2(0.5f, 1.0f)); 

    // 
    // Add a set of key frames to describe how the Offset should change over time.   
    // 

    animation.InsertKeyFrame(0.00f, new Vector3(100.0f, 100.0f, 0.0f)); 
    animation.InsertKeyFrame(0.25f, new Vector3(300.0f, 100.0f, 0.0f), easeIn); 
    animation.InsertKeyFrame(0.50f, new Vector3(300.0f, 300.0f, 0.0f), linear); 
    animation.InsertKeyFrame(0.75f, new Vector3(100.0f, 300.0f, 0.0f), linear); 
    animation.InsertKeyFrame(1.00f, new Vector3(100.0f, 100.0f, 0.0f), easeOut); 

    // 
    // The animation curve defined by the key frames will scale to match the duration. 
    // 

    animation.Duration = TimeSpan.FromMilliseconds(4000); 

    targetVisual.StartAnimation("Offset", animation); 
} 

Remarks

If an animation is already bound to an object's property when StartAnimation is called, the previous applied animation will be disconnected and the new animation will be assigned. Similarly, setting the property directly will cause the previous animation to be disconnected and the new property value will take effect.

The following table shows the list of animatable properties:

Object Property Name Property Type
Visual AnchorPoint Vector2
CenterPoint Vector3
Offset Vector3
Opacity Scalar
Orientation Vector4
RotationAngle Scalar
RotationAxis Vector3
Size Vector2
TransformMatrix Matrix4x4
InsetClip BottomInset Scalar
LeftInset Scalar
RightInset Scalar
TopInset Scalar
CompositionColorBrush Color Windows.UI.Color
CompositionPropertySet Set of properties specified by the developer.

In addition, properties of some effects under the CompositionEffectBrush object can be animated:

Effect Name Property Name Property Type
SaturationEffect Saturation Scalar
ColorSourceEffect Color Vector4
ArithmeticComposite Offset Scalar
Source1Amount Scalar
Source2Amount Scalar
MultiplyAmount Scalar
Transform2D TransformMatrix Matrix3x2
ContrastEffect Contrast Float
ExposureEffect Exposure Float
HueRotationEffect Angle Float
SepiaEffect Intensity Float
TemperatureAndTintEffect Temperature Float
Tint Float
GammaTransferEffect RedAmplitude Float
RedExponent Float
RedOffset Float
GreenAmplitude Float
GreenExponent Float
GreenOffset Float
BlueAmplitude Float
BlueExponent Float
BlueOffset Float
AlphaAmplitude Float
AlphaExponent Float
AlphaOffset Float

Applies to

StartAnimation(String, CompositionAnimation, AnimationController)

Connects an animation with the specified property of the object and starts the animation.

public:
 virtual void StartAnimation(Platform::String ^ propertyName, CompositionAnimation ^ animation, AnimationController ^ animationController) = StartAnimation;
/// [Windows.Foundation.Metadata.Overload("StartAnimationWithController")]
void StartAnimation(winrt::hstring const& propertyName, CompositionAnimation const& animation, AnimationController const& animationController);
[Windows.Foundation.Metadata.Overload("StartAnimationWithController")]
public void StartAnimation(string propertyName, CompositionAnimation animation, AnimationController animationController);
function startAnimation(propertyName, animation, animationController)
Public Sub StartAnimation (propertyName As String, animation As CompositionAnimation, animationController As AnimationController)

Parameters

propertyName
String

Platform::String

winrt::hstring

The property to associate the animation with.

animation
CompositionAnimation

The animation to associate with the specified property.

animationController
AnimationController

The animation controller to associate with the animation.

Attributes

Windows requirements

Device family
Windows 11 Insider Preview (introduced in 10.0.23504.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v15.0)

Remarks

The animationController parameter lets you bind multiple animations to a single controller's Progress property, which requires fewer ExpressionAnimation objects than binding multiple animator's Progress properties to a CompositionObject property.

Applies to