-api-id | -api-type |
---|---|
M:Windows.UI.Composition.CompositionObject.StartAnimation(System.String,Windows.UI.Composition.CompositionAnimation) |
winrt method |
Connects an animation with the specified property of the object and starts the animation.
The property to associate the animation with.
The animation to associate with the specified property.
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 |
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);
}