I created an animation storyboard in xaml file. That story board begins on Button.Click. But to stop the animation I am trying to stop storyboard on my custom event in code
I am thankful for Timothy for giving nice Idea. Here I am posting my working code
/*create this resources as global to that perticular xaml. Need not to be put it in App.xaml
MyControl could be Window or Page or UserControl */
/* */
/* */
/* ****************************************************************** */
/* Code behind to start/stop animation*/
//Get the resource value first on current object, so that when you start/stop the animation, it work only on current object
Storyboard sbImageAnimate = (Storyboard)this.ServerView.FindResource("MovingServer");
//Start the animation on Button Click
protected void Scanbutton_Click(object Sender, EventArgs e)
{
this.MyImage.Visibility = System.Windows.Visibility.Visible;
sbImageAnimate.Begin();
}
//Stop animation on my own even. You can use it on any event
private void EventPublisher_OnFinish(object sender, EventArgs args)
{
Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { this.StopScanningAnimation(); });
}
private void StopScanningAnimation()
{
sbImageAnimate.Stop();
this.MyImage.Visibility = System.Windows.Visibility.Hidden;
}