鑑於我的動畫scene1
。如何使用名爲「跳過」的按鈕在後面使用C# code
進行暫停,然後播放另一個動畫scene2
。如何使用後面的代碼暫停wpf動畫?
<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.)
謝謝..我想暫停它的當前位置..所以暫停是我需要的東西......與我回復傑裏克scene1時自動啓動時窗體加載...我想通過跳過按鈕使用代碼手動停止它,同時播放scene2 ...這可能嗎? – mitche027
當然是!就像這樣調用場景2:Storyboard scene2 = this.Resources [「scene2」] as Storyboard;併發揮它。你可以按照你的喜好慢跑。 – HichemSeeSharp
它真的幫了很多..但暫停後出現一個錯誤消息「對象引用未設置爲對象的實例。」該錯誤指出我的代碼爲暫停按鈕,它是:Storyboard scene1 = this.Resources [「scene_1」]作爲Storyboard; scene1.Pause(); – mitche027