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 時動畫已經系結至物件的 屬性,則會中斷先前套用的動畫,並指派新的動畫。 同樣地,直接設定屬性會導致先前的動畫中斷連線,而新的屬性值將會生效。

下表顯示可產生動畫屬性的清單:

Object 屬性名稱 屬性類型
視覺效果 AnchorPoint Vector2
--- CenterPoint Vector3
--- Offset Vector3
--- 不透明度 純量
--- 方向 Vector4
--- RotationAngle 純量
--- RotationAxis Vector3
--- 大小 Vector2
--- TransformMatrix Matrix4x4
InsetClip BottomInset 純量
--- LeftInset 純量
--- RightInset 純量
--- TopInset 純量
CompositionColorBrush Color Windows.UI.Color
CompositionPropertySet 開發人員指定的屬性集。

此外, CompositionEffectBrush 物件下某些效果的屬性可以產生動畫效果:

效果名稱 屬性名稱 屬性類型
SaturationEffect 飽和度 純量
ColorSourceEffect 色彩 Vector4
算術Composite Offset 純量
--- Source1Amount 純量
--- Source2Amount 純量
--- MultiplyAmount 純量
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 物件。

適用於