CompositionObject.StartAnimation 方法

定義

多載

名稱 Description
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 時,動畫已經綁定在物件屬性上,那麼先前套用的動畫會被斷開連接,並重新指派新的動畫。 同樣地,直接設定屬性會讓先前的動畫斷開,新的屬性值會生效。

下表顯示可動畫性質的列表:

物件 屬性名稱 屬性類型
Visual 錨點 向量2
--- CenterPoint Vector3
--- 偏移 Vector3
--- 不透明度 Scalar
--- 方向 向量4
--- 旋轉角 Scalar
--- 旋轉軸 Vector3
--- 大小 向量2
--- TransformMatrix Matrix4x4
嵌剪輯 底部插圖 Scalar
--- 左插圖 Scalar
--- 右插 Scalar
--- 頂嵌 Scalar
CompositionColorBrush Color Windows。UI。顏色
CompositionPropertySet 由開發者指定的屬性集合。

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

效應名稱 屬性名稱 屬性類型
飽和效應 飽和度 Scalar
色彩來源效果 顏色 向量4
算術綜合 偏移 Scalar
--- 來源1金額 Scalar
--- 來源2Amount Scalar
--- 乘法 Scalar
Transform2D TransformMatrix 矩陣3x2
對比效果 對比 浮動
曝光效應 暴露 浮動
色相旋轉效應 角度 浮動
棕褐效果 強度 浮動
溫度與色調效應 溫度 浮動
--- 貼膜 浮動
伽瑪轉移效應 紅振幅 浮動
--- RedExponent 浮動
--- RedOffset(紅偏移) 浮動
--- 綠色振幅 浮動
--- 綠色指數 浮動
--- 綠色偏移 浮動
--- 藍色振幅 浮動
--- BlueExponent 浮動
--- 藍色偏移 浮動
--- 阿爾法振幅 浮動
--- AlphaExponent 浮動
--- AlphaOffset(阿爾法偏移) 浮動

適用於

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 物件數量少。

適用於