如何使用代码隐藏暂停wpf动画?
给定我的动画如何使用代码隐藏暂停wpf动画?,wpf,animation,Wpf,Animation,给定我的动画场景1。如何使用名为“跳过”的按钮在后面使用C#code暂停,然后在后面播放另一个动画scene2 <Window.Resources> <Storyboard x:Key="scene1"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="whitebox">
场景1
。如何使用名为“跳过”的按钮在后面使用C#code
暂停,然后在后面播放另一个动画scene2
<Window.Resources>
<Storyboard x:Key="scene1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="whitebox">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.7" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="charName">
<DiscreteStringKeyFrame KeyTime="0:0:2" Value="Teacher"/>
<DiscreteStringKeyFrame KeyTime="0:0:7.8" Value="Teacher"/>
<DiscreteStringKeyFrame KeyTime="0:0:8" Value="Teacher"/>
</StringAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="charName">
<DiscreteObjectKeyFrame KeyTime="0:0:2" Value="{x:Static HorizontalAlignment.Left}"/>
<DiscreteObjectKeyFrame KeyTime="0:0:7.8" Value="{x:Static HorizontalAlignment.Left}"/>
<DiscreteObjectKeyFrame KeyTime="0:0:8" Value="{x:Static HorizontalAlignment.Left}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
(too long… etc.)
在代码隐藏中,使用此.Resources[“scene1”]获取情节提要对象
Storyboard storyBoard = this.Resources["scene1"] as Storyboard;
storyBoard.Begin();
在情节提要完成后,使用情节提要“已完成”事件启动另一个动画
storyBoard.Completed += eventHandler
召唤
停止动画。除了Jeric Paul Calderon的答案外,还有暂停功能:storyBoard.pause()
主要是Pause()
在当前播放位置暂停annimation,并且Stop()
确实停止并返回到起始点。好的,当表单加载时,scene1会自动启动。。。我想通过跳过按钮使用代码隐藏手动停止它,同时播放场景2。。。有可能吗?谢谢。。我想在它的当前位置暂停它。。所以暂停是我需要的…就像我对Jeric scene1的回复一样,当表单加载时会自动启动。。。我想通过跳过按钮使用代码隐藏手动停止它,同时播放场景2。。。有可能吗?当然有!只需这样调用场景2:Storyboard scene2=this.Resources[“scene2”]作为故事板;而且一定要玩。你可以和我一起慢跑,随你的便。这真的帮了大忙。。但是在暂停之后,出现了一条错误消息“对象引用未设置为对象的实例”。错误指出了暂停按钮的代码,即:Storyboard scene1=this.Resources[“scene_1”]作为Storyboard;场景1.暂停();
storyBoard.Stop()