UIElement.BeginAnimation UIElement.BeginAnimation UIElement.BeginAnimation UIElement.BeginAnimation Method

定義

針對這個項目之指定的動畫屬性,開始播放動畫。Starts an animation for a specified animated property on this element.

多載

BeginAnimation(DependencyProperty, AnimationTimeline) BeginAnimation(DependencyProperty, AnimationTimeline) BeginAnimation(DependencyProperty, AnimationTimeline) BeginAnimation(DependencyProperty, AnimationTimeline)

針對這個項目之指定的動畫屬性,開始播放動畫。Starts an animation for a specified animated property on this element.

BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior) BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior) BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)

針對此項目上指定的動畫屬性啟動特定動畫,且可以選擇指定如果屬性已經有執行中的動畫時會發生何種情況。Starts a specific animation for a specified animated property on this element, with the option of specifying what happens if the property already has a running animation.

BeginAnimation(DependencyProperty, AnimationTimeline) BeginAnimation(DependencyProperty, AnimationTimeline) BeginAnimation(DependencyProperty, AnimationTimeline) BeginAnimation(DependencyProperty, AnimationTimeline)

針對這個項目之指定的動畫屬性,開始播放動畫。Starts an animation for a specified animated property on this element.

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 DependencyProperty DependencyProperty DependencyProperty

要顯示動畫的屬性,該屬性會指定為相依性屬性識別項。The property to animate, which is specified as a dependency property identifier.

animation
AnimationTimeline AnimationTimeline AnimationTimeline AnimationTimeline

啟動動畫的時刻表。The timeline of the animation to start.

實作

範例

下列範例會建立動畫、將它指派給, 然後呼叫BeginAnimation來啟動它。The following example creates an animation, assigns it, and then calls BeginAnimation to start it.

// 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)

備註

當您檢查屬性是否為動畫時, 請注意動畫將會開始, 並在呈現非動畫起點以外的第一個畫面格時, 將其視為動畫。When you check whether a property is animated, note that the animation will begin and be considered animated when the first frame beyond the non-animated starting point is rendered.

animation如果的BeginTime 為,則會移除任何目前的動畫,並保留屬性null的目前值。If the BeginTime for animation is null, then any current animations are removed and the current value of the property is held.

如果整個animation值為null, 則會從屬性中移除所有動畫, 並將屬性值還原為其基底值。If the entire animation value is null, all animations are removed from the property and the property value reverts to its base value. 不過, 原先關聯的動畫時間軸不會停止。However, the originally associated animation timeline is not stopped. 任何其他指派給該時間軸的動畫都會繼續執行。Any other animations assigned to that timeline will continue to run.

BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior) BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior) BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)

針對此項目上指定的動畫屬性啟動特定動畫,且可以選擇指定如果屬性已經有執行中的動畫時會發生何種情況。Starts a specific animation for a specified animated property on this element, with the option of specifying what happens if the property already has a running animation.

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

參數

dp
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

要顯示動畫的屬性,該屬性會指定為相依性屬性識別項。The property to animate, which is specified as the dependency property identifier.

animation
AnimationTimeline AnimationTimeline AnimationTimeline AnimationTimeline

套用動畫的時刻表。The timeline of the animation to be applied.

handoffBehavior
HandoffBehavior HandoffBehavior HandoffBehavior HandoffBehavior

一個列舉值,這個值指定新的動畫如何與已經影響屬性值的任何目前 (執行中) 動畫互動。A value of the enumeration that specifies how the new animation interacts with any current (running) animations that are already affecting the property value.

實作

範例

下列範例會執行可從資源取得現有動畫的處理常式, 然後再呼叫BeginAnimation具有指定之遞交行為的。The following example implements a handler that obtains an existing animation from a resource and then calls BeginAnimation with a specified handoff behavior.

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

備註

當您檢查屬性是否為動畫時, 請注意動畫將會開始, 並在呈現非動畫起點以外的第一個畫面格時, 將其視為動畫。When you check whether a property is animated, note that the animation will begin and be considered animated when the first frame beyond the non-animated starting point is rendered.

animation如果的BeginTime 為,則會移除任何目前的動畫,並保留屬性null的目前值。If the BeginTime for animation is null, then any current animations are removed and the current value of the property is held.

如果整個animation值為null, 則會從屬性中移除所有動畫, 並將屬性值還原為其基底值。If the entire animation value is null, all animations are removed from the property and the property value reverts to its base value. 不過, 原先關聯的動畫時間軸不會停止。However, the originally associated animation timeline is not stopped. 任何其他指派給該時間軸的動畫都會繼續執行。Any other animations assigned to that timeline will continue to run.

適用於