Share via


CompositionObject.StartAnimation 方法

定义

重载

StartAnimation(String, CompositionAnimation)

将动画与 对象的指定属性连接,并启动动画。

StartAnimation(String, CompositionAnimation, AnimationController)

将动画与 对象的指定属性连接,并启动动画。

StartAnimation(String, CompositionAnimation)

使用 对象的指定属性连接动画并启动动画。

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)

参数

propertyName
String

Platform::String

winrt::hstring

要与动画关联的属性。

animation
CompositionAnimation

要与指定属性关联的动画。

示例

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); 
}     

注解

如果在调用 StartAnimation 时,动画已绑定到对象的 属性,则之前应用的动画将断开连接,并将分配新动画。 同样,直接设置 属性将导致上一个动画断开连接,并且新属性值将生效。

下表显示了可进行动画处理的属性列表:

对象 属性名称 属性类型
视觉对象 AnchorPoint Vector2
--- CenterPoint Vector3
--- Offset Vector3
--- 不透明度 Scalar
--- 方向 Vector4
--- RotationAngle Scalar
--- RotationAxis Vector3
--- 大小 Vector2
--- TransformMatrix Matrix4x4
InsetClip BottomInset Scalar
--- LeftInset Scalar
--- RightInset Scalar
--- TopInset Scalar
CompositionColorBrush 彩色 Windows.UI.Color
CompositionPropertySet 开发人员指定的属性集。

此外,可以对 CompositionEffectBrush 对象下某些效果的属性进行动画处理:

效果名称 属性名称 属性类型
饱和效果 饱和度 Scalar
ColorSourceEffect 颜色 Vector4
ArithmeticComposite Offset Scalar
--- Source1Amount Scalar
--- Source2Amount Scalar
--- MultiplyAmount Scalar
Transform2D TransformMatrix Matrix3x2
ContrastEffect 与此示例 Float
ExposureEffect 曝光 Float
HueRotationEffect 角度 Float
SepiaEffect 强度 Float
TemperatureAndTintEffect 温度 Float
--- 色调 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

适用于

StartAnimation(String, CompositionAnimation, AnimationController)

使用 对象的指定属性连接动画并启动动画。

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)

参数

propertyName
String

Platform::String

winrt::hstring

要与之关联的动画的属性。

animation
CompositionAnimation

要与指定属性关联的动画。

animationController
AnimationController

要与动画关联的动画控制器。

属性

注解

参数 animationController 允许将多个动画绑定到单个控制器的 Progress 属性,这比将多个动画器 Progress 的属性绑定到 CompositionObject 属性所需的 ExpressionAnimation 对象更少。

适用于