FrameworkElement.BeginStoryboard 方法

定义

开始所提供的演示图板中包含的操作序列。Begins the sequence of actions contained in the provided storyboard.

重载

BeginStoryboard(Storyboard)

开始所提供的演示图板中包含的操作序列。Begins the sequence of actions that are contained in the provided storyboard.

BeginStoryboard(Storyboard, HandoffBehavior)

开始所提供的演示图板中包含的操作序列,并指定选项来指明当已对属性进行动画处理时应发生的行为。Begins the sequence of actions contained in the provided storyboard, with options specified for what should happen if the property is already animated.

BeginStoryboard(Storyboard, HandoffBehavior, Boolean)

开始所提供的演示图板中包含的操作序列,并使动画控件在动画开始后具有指定的状态。Begins the sequence of actions contained in the provided storyboard, with specified state for control of the animation after it is started.

BeginStoryboard(Storyboard)

开始所提供的演示图板中包含的操作序列。Begins the sequence of actions that are contained in the provided storyboard.

public:
 void BeginStoryboard(System::Windows::Media::Animation::Storyboard ^ storyboard);
public void BeginStoryboard (System.Windows.Media.Animation.Storyboard storyboard);
member this.BeginStoryboard : System.Windows.Media.Animation.Storyboard -> unit

参数

storyboard
Storyboard

要开始的演示图板。The storyboard to begin.

示例

下面的示例从资源中检索 Storyboard,然后在对内部事件进行类处理时运行 StoryboardThe following example retrieves a Storyboard from resources, and then runs that Storyboard when an internal event is class handled.

private void OnImage1Animate(object sender, RoutedEventArgs e)
{
    Storyboard s;

    s = (Storyboard)this.FindResource("RotateStoryboard");
    this.BeginStoryboard(s);
}
Private Sub OnImage1Animate(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim s As Storyboard

    s = CType(Me.FindResource("RotateStoryboard"), Storyboard)
    Me.BeginStoryboard(s)
End Sub

注解

最典型的动画方案不使用此方法。Most typical animation scenarios do not use this method. 通常,您将在标记中创建 StoryboardBeginStoryboard 元素,然后将它们放置为元素上的 EventTrigger 内容。Typically, you create the Storyboard or BeginStoryboard element in markup, and then you place these as the EventTrigger content on an element. 当事件触发时,动画将运行。When triggered by the event, the animation then runs. Storyboard 的大部分控制方面都可以通过在标记中公开的属性进行寻址。Most of the control aspects of a Storyboard can be addressed by properties that are exposed in markup.

对于不使用 isControllable、参数或指定该参数的签名 false,一旦动画达到 "填充" 时间段,就会删除与动画关联的时间线时钟。For the signatures that do not use the isControllable, parameter, or when that parameter is specified false, the timeline clocks that are associated with the animation are removed as soon as the animation reaches the "Fill" period. 因此,不能在运行后重新启动动画。Therefore the animation cannot be restarted after running once. 控制动画还要求情节提要具有X:Name 指令或可通过代码中的引用进行访问。Controlling an animation also requires that the storyboard have an x:Name Directive or be accessible by reference in code.

BeginStoryboard(Storyboard, HandoffBehavior)

开始所提供的演示图板中包含的操作序列,并指定选项来指明当已对属性进行动画处理时应发生的行为。Begins the sequence of actions contained in the provided storyboard, with options specified for what should happen if the property is already animated.

public:
 void BeginStoryboard(System::Windows::Media::Animation::Storyboard ^ storyboard, System::Windows::Media::Animation::HandoffBehavior handoffBehavior);
public void BeginStoryboard (System.Windows.Media.Animation.Storyboard storyboard, System.Windows.Media.Animation.HandoffBehavior handoffBehavior);
member this.BeginStoryboard : System.Windows.Media.Animation.Storyboard * System.Windows.Media.Animation.HandoffBehavior -> unit

参数

storyboard
Storyboard

要开始的演示图板。The storyboard to begin.

handoffBehavior
HandoffBehavior

一个枚举值,该值描述演示图板中描述的属性在经过动画处理后要使用的行为。A value of the enumeration that describes behavior to use if a property described in the storyboard is already animated.

示例

下面的示例从资源中检索 Storyboard,然后在对内部事件进行类处理时运行 StoryboardThe following example retrieves a Storyboard from resources, and then runs that Storyboard when an internal event is class handled.

private void OnImage1Animate(object sender, RoutedEventArgs e)
{
    Storyboard s;

    s = (Storyboard)this.FindResource("RotateStoryboard");
    this.BeginStoryboard(s);
}
Private Sub OnImage1Animate(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim s As Storyboard

    s = CType(Me.FindResource("RotateStoryboard"), Storyboard)
    Me.BeginStoryboard(s)
End Sub

注解

最典型的动画方案不使用此方法。Most typical animation scenarios do not use this method. 通常,您将在标记中创建 StoryboardBeginStoryboard 元素,然后将它们放置为元素上的 EventTrigger 内容。Typically, you create the Storyboard or BeginStoryboard element in markup, and then you place these as the EventTrigger content on an element. 当事件触发时,动画将运行。When triggered by the event, the animation then runs. Storyboard 的大部分控制方面都可以通过在标记中公开的属性进行寻址。Most of the control aspects of a Storyboard can be addressed by properties that are exposed in markup.

对于不使用 isControllable、参数或指定该参数的签名 false,一旦动画达到 "填充" 时间段,就会删除与动画关联的时间线时钟。For the signatures that do not use the isControllable, parameter, or when that parameter is specified false, the timeline clocks that are associated with the animation are removed as soon as the animation reaches the "Fill" period. 因此,不能在运行后重新启动动画。Therefore the animation cannot be restarted after running once. 控制动画还要求情节提要具有X:Name 指令或可通过代码中的引用进行访问。Controlling an animation also requires that the storyboard have an x:Name Directive or be accessible by reference in code.

可以将移交行为指定为 BeginStoryboard的属性。Handoff behavior can be specified as an attribute of BeginStoryboard.

使用撰写 HandoffBehaviorUsing the Compose HandoffBehavior

使用 Compose HandoffBehaviorStoryboardAnimationTimelineAnimationClock 应用于属性时,以前与该属性关联的任何 Clock 对象将继续使用系统资源;计时系统不会自动删除时钟。When you apply a Storyboard, AnimationTimeline, or AnimationClock to a property by using the Compose HandoffBehavior, any Clock objects previously associated with that property continue to consume system resources; the timing system does not remove the clocks automatically.

为了避免在使用 Compose应用大量时钟时出现性能问题,应在完成后从动画属性中删除组合时钟。To avoid performance issues when you apply a large number of clocks by using Compose, you should remove composing clocks from the animated property after they complete. 有几种方法可以删除时钟:There are several ways to remove a clock:

此动画问题主要出现在生存期较长的对象上。This is primarily an issue for animations on objects that have a long lifetime. 当对对象进行垃圾回收时,还会断开其时钟的连接并对其进行垃圾回收。When an object is garbage collected, its clocks are also disconnected and garbage collected.

有关时钟对象的详细信息,请参阅动画和计时系统概述For more information about clock objects, see Animation and Timing System Overview.

BeginStoryboard(Storyboard, HandoffBehavior, Boolean)

开始所提供的演示图板中包含的操作序列,并使动画控件在动画开始后具有指定的状态。Begins the sequence of actions contained in the provided storyboard, with specified state for control of the animation after it is started.

public:
 void BeginStoryboard(System::Windows::Media::Animation::Storyboard ^ storyboard, System::Windows::Media::Animation::HandoffBehavior handoffBehavior, bool isControllable);
public void BeginStoryboard (System.Windows.Media.Animation.Storyboard storyboard, System.Windows.Media.Animation.HandoffBehavior handoffBehavior, bool isControllable);
member this.BeginStoryboard : System.Windows.Media.Animation.Storyboard * System.Windows.Media.Animation.HandoffBehavior * bool -> unit

参数

storyboard
Storyboard

要开始的演示图板。The storyboard to begin.

handoffBehavior
HandoffBehavior

一个枚举值,该值描述演示图板中描述的属性在经过动画处理后要使用的行为。A value of the enumeration that describes behavior to use if a property described in the storyboard is already animated.

isControllable
Boolean

声明在动画开始后是否仍可以对它进行控制(可以暂停)。Declares whether the animation is controllable (can be paused) after it is started.

注解

最典型的动画方案不使用此方法。Most typical animation scenarios do not use this method. 通常,您将在标记中创建 StoryboardBeginStoryboard 元素,然后将它们放置为元素上的 EventTrigger 内容。Typically, you create the Storyboard or BeginStoryboard element in markup, and then you place these as the EventTrigger content on an element. 当事件触发时,动画将运行。When triggered by the event, the animation then runs. Storyboard 的大部分控制方面都可以通过在标记中公开的属性进行寻址。Most of the control aspects of a Storyboard can be addressed by properties that are exposed in markup.

对于不使用 isControllable、参数或指定该参数的签名 false,一旦动画达到 "填充" 时间段,就会删除与动画关联的时间线时钟。For the signatures that do not use the isControllable, parameter, or when that parameter is specified false, the timeline clocks that are associated with the animation are removed as soon as the animation reaches the "Fill" period. 因此,不能在运行后重新启动动画。Therefore the animation cannot be restarted after running once. 控制动画还要求情节提要具有X:Name 指令或可通过代码中的引用进行访问。Controlling an animation also requires that the storyboard have an x:Name Directive or be accessible by reference in code.

可以将移交行为指定为 BeginStoryboard的属性。Handoff behavior can be specified as an attribute of BeginStoryboard.

使用撰写 HandoffBehaviorUsing the Compose HandoffBehavior

使用 Compose HandoffBehaviorStoryboardAnimationTimelineAnimationClock 应用于属性时,以前与该属性关联的任何 Clock 对象将继续使用系统资源;计时系统不会自动删除时钟。When you apply a Storyboard, AnimationTimeline, or AnimationClock to a property by using the Compose HandoffBehavior, any Clock objects previously associated with that property continue to consume system resources; the timing system does not remove the clocks automatically.

为了避免在使用 Compose应用大量时钟时出现性能问题,应在完成后从动画属性中删除组合时钟。To avoid performance issues when you apply a large number of clocks by using Compose, you should remove composing clocks from the animated property after they complete. 有几种方法可以删除时钟:There are several ways to remove a clock:

此动画问题主要出现在生存期较长的对象上。This is primarily an issue for animations on objects that have a long lifetime. 当对对象进行垃圾回收时,还会断开其时钟的连接并对其进行垃圾回收。When an object is garbage collected, its clocks are also disconnected and garbage collected.

有关时钟对象的详细信息,请参阅动画和计时系统概述For more information about clock objects, see Animation and Timing System Overview.

适用于