WPF Reset Storyboard When Selecting Again

1.7k views Asked by At

How to set back a storyboard just like when the page is loaded? My situation here, at the same page I have 2 animation. For button A and button B. Both button will run a storyboard eg: NavigateMyCar_A and NavigateMyCar_B.

If I click button A, it will run a NavigateMyCar_A storyboard. If I click button B, it will run a NavigateMyCar_B storyboard.

And if click back the button A, the storyboard will appear as the finish timeline. How do I reset back the position of the timeline? Below are what I do everytime it want to begin a storyboard but still on the last frame.

Dim mystoryboard As New Storyboard
mystoryboard = CType(Me.Resources("NavigateMyCar_A"), Storyboard)
mystoryboard.Seek(TimeSpan.Zero, TimeSeekOrigin.BeginTime)
mystoryboard.Stop()
mystoryboard.Begin(Me)
  • I already seek answer on google and tried it. And what I post here is what I try but not succeed. Kindly help. TQ

EDITED: After click button A, it will run another animation call "View_Animation" to view the result and user press button "NAVIGATE" and NavigateMyCar_A will start. Same function apply to button B. But when it comes back to button A, it will view result under "View_Animation" but the navigation of car A is finish already before hit the NAVIGATE button..I do animation after animation programatically

1

There are 1 answers

0
King King On

I see that you use the Begin method with the Me passed in. So to control the Storyboard, you have to use the Seek method without that same containing element passed in. Something like this:

mystoryboard.Seek(Me, TimeSpan.Zero, TimeSeekOrigin.BeginTime)

That's just simple like that. In case the Begin method is called like this Begin() (without any argument), then your original code will work.