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.

适用于