CompositionObject.StartAnimation(String, CompositionAnimation) Method

Definition

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);
Public Sub StartAnimation (propertyName As String, animation As CompositionAnimation)

Parameters

propertyName
String

The property to associate the animation with.

animation
CompositionAnimation

The animation to associate with the specified property.

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:

ObjectProperty NameProperty Type
@"Microsoft.UI.Composition.Visual?text=Visual" @"Microsoft.UI.Composition.Visual.AnchorPoint?text=AnchorPoint" Vector2
@"Microsoft.UI.Composition.Visual.CenterPoint?text=CenterPoint" Vector3
@"Microsoft.UI.Composition.Visual.Offset?text=Offset" Vector3
@"Microsoft.UI.Composition.Visual.Opacity?text=Opacity" Scalar
@"Microsoft.UI.Composition.Visual.Orientation?text=Orientation" Vector4
@"Microsoft.UI.Composition.Visual.RotationAngle?text=RotationAngle" Scalar
@"Microsoft.UI.Composition.Visual.RotationAxis?text=RotationAxis" Vector3
@"Microsoft.UI.Composition.Visual.Size?text=Size" Vector2
@"Microsoft.UI.Composition.Visual.TransformMatrix?text=TransformMatrix" Matrix4x4
@"Microsoft.UI.Composition.InsetClip?text=InsetClip" @"Microsoft.UI.Composition.InsetClip.BottomInset?text=BottomInset" Scalar
@"Microsoft.UI.Composition.InsetClip.LeftInset?text=LeftInset" Scalar
@"Microsoft.UI.Composition.InsetClip.RightInset?text=RightInset" Scalar
@"Microsoft.UI.Composition.InsetClip.TopInset?text=TopInset" Scalar
@"Microsoft.UI.Composition.CompositionColorBrush?text=CompositionColorBrush" @"Microsoft.UI.Composition.CompositionColorBrush.Color?text=Color" Windows.UI.Color
@"Microsoft.UI.Composition.CompositionPropertySet?text=CompositionPropertySet" Set of properties specified by the developer.

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

Effect NameProperty NameProperty Type
SaturationEffectSaturationScalar
ColorSourceEffectColorVector4
ArithmeticCompositeOffsetScalar
Source1AmountScalar
Source2AmountScalar
MultiplyAmountScalar
Transform2DTransformMatrixMatrix3x2
ContrastEffectContrastFloat
ExposureEffectExposureFloat
HueRotationEffectAngleFloat
SepiaEffectIntensityFloat
TemperatureAndTintEffectTemperatureFloat
TintFloat
GammaTransferEffectRedAmplitudeFloat
RedExponentFloat
RedOffsetFloat
GreenAmplitudeFloat
GreenExponentFloat
GreenOffsetFloat
BlueAmplitudeFloat
BlueExponentFloat
BlueOffsetFloat
AlphaAmplitudeFloat
AlphaExponentFloat
AlphaOffsetFloat

Applies to