UIElement.BeginAnimation 方法

定義

針對這個項目之指定的動畫屬性,開始播放動畫。

多載

BeginAnimation(DependencyProperty, AnimationTimeline)

針對這個項目之指定的動畫屬性,開始播放動畫。

BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)

針對此項目上指定的動畫屬性啟動特定動畫,且可以選擇指定如果屬性已經有執行中的動畫時會發生何種情況。

BeginAnimation(DependencyProperty, AnimationTimeline)

針對這個項目之指定的動畫屬性,開始播放動畫。

public:
 virtual void BeginAnimation(System::Windows::DependencyProperty ^ dp, System::Windows::Media::Animation::AnimationTimeline ^ animation);
public void BeginAnimation (System.Windows.DependencyProperty dp, System.Windows.Media.Animation.AnimationTimeline animation);
abstract member BeginAnimation : System.Windows.DependencyProperty * System.Windows.Media.Animation.AnimationTimeline -> unit
override this.BeginAnimation : System.Windows.DependencyProperty * System.Windows.Media.Animation.AnimationTimeline -> unit
Public Sub BeginAnimation (dp As DependencyProperty, animation As AnimationTimeline)

參數

dp
DependencyProperty

要顯示動畫的屬性,該屬性會指定為相依性屬性識別項。

animation
AnimationTimeline

啟動動畫的時刻表。

實作

範例

下列範例會建立動畫、指派動畫,然後呼叫 BeginAnimation 來啟動它。

// Animate the button's width.
DoubleAnimation widthAnimation = 
    new DoubleAnimation(120, 300, TimeSpan.FromSeconds(5));
widthAnimation.RepeatBehavior = RepeatBehavior.Forever;
widthAnimation.AutoReverse = true;
animatedButton.BeginAnimation(Button.WidthProperty, widthAnimation);
' Animate the button's width.
Dim widthAnimation As New DoubleAnimation(120, 300, TimeSpan.FromSeconds(5))
widthAnimation.RepeatBehavior = RepeatBehavior.Forever
widthAnimation.AutoReverse = True
animatedButton.BeginAnimation(Button.WidthProperty, widthAnimation)

備註

當您檢查屬性是否為動畫時,請注意,當非動畫起點以外的第一個畫面呈現時,動畫會開始並視為動畫。

BeginTime如果 的 animationnull ,則會移除任何目前的動畫,並保留屬性的目前值。

如果整個 animation 值為 null ,則會從 屬性中移除所有動畫,而 屬性值會還原為其基底值。 不過,原始關聯的動畫時間軸不會停止。 指派給該時程表的任何其他動畫都會繼續執行。

適用於

BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)

針對此項目上指定的動畫屬性啟動特定動畫,且可以選擇指定如果屬性已經有執行中的動畫時會發生何種情況。

public:
 virtual void BeginAnimation(System::Windows::DependencyProperty ^ dp, System::Windows::Media::Animation::AnimationTimeline ^ animation, System::Windows::Media::Animation::HandoffBehavior handoffBehavior);
public void BeginAnimation (System.Windows.DependencyProperty dp, System.Windows.Media.Animation.AnimationTimeline animation, System.Windows.Media.Animation.HandoffBehavior handoffBehavior);
abstract member BeginAnimation : System.Windows.DependencyProperty * System.Windows.Media.Animation.AnimationTimeline * System.Windows.Media.Animation.HandoffBehavior -> unit
override this.BeginAnimation : System.Windows.DependencyProperty * System.Windows.Media.Animation.AnimationTimeline * System.Windows.Media.Animation.HandoffBehavior -> unit
Public Sub BeginAnimation (dp As DependencyProperty, animation As AnimationTimeline, handoffBehavior As HandoffBehavior)

參數

dp
DependencyProperty

要顯示動畫的屬性,該屬性會指定為相依性屬性識別項。

animation
AnimationTimeline

套用動畫的時刻表。

handoffBehavior
HandoffBehavior

一個列舉值,這個值指定新的動畫如何與已經影響屬性值的任何目前 (執行中) 動畫互動。

實作

範例

下列範例會實作處理常式,從資源取得現有的動畫,然後使用指定的遞交行為呼叫 BeginAnimation

private void myFrameNavigated(object sender, NavigationEventArgs args)
{
    DoubleAnimation myFadeInAnimation = (DoubleAnimation)this.Resources["MyFadeInAnimationResource"];
    myFrame.BeginAnimation(Frame.OpacityProperty, myFadeInAnimation, HandoffBehavior.SnapshotAndReplace);
}
Private Sub myFrameNavigated(ByVal sender As Object, ByVal args As NavigationEventArgs)
    Dim myFadeInAnimation As DoubleAnimation = CType(Me.Resources("MyFadeInAnimationResource"), DoubleAnimation)
    myFrame.BeginAnimation(Frame.OpacityProperty, myFadeInAnimation, HandoffBehavior.SnapshotAndReplace)
End Sub

備註

當您檢查屬性是否為動畫時,請注意,當非動畫起點以外的第一個畫面呈現時,動畫會開始並視為動畫。

BeginTime如果 的 animationnull ,則會移除任何目前的動畫,並保留屬性的目前值。

如果整個 animation 值為 null ,則會從 屬性中移除所有動畫,而 屬性值會還原為其基底值。 不過,原始關聯的動畫時間軸不會停止。 指派給該時程表的任何其他動畫都會繼續執行。

適用於