I am able to provide animation to an image button from below code.
this.RegisterName(image1.Name, image1);
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 1.0;
myDoubleAnimation.To = 0.0;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.25));
myDoubleAnimation.AutoReverse = true;
myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
myStoryboard = new Storyboard();
myStoryboard.Children.Add(myDoubleAnimation);
Storyboard.SetTargetName(myDoubleAnimation, image1.Name);
Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Image.OpacityProperty));
myStoryboard.Begin(this);
Now I need to stop the animation .
Below is the sample code.
TimeSpan? ts = new TimeSpan(0,0,2);
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 1.0;
myDoubleAnimation.To = 0.0;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));
myStoryboard.BeginTime = ts;
myDoubleAnimation.AutoReverse = true;
myStoryboard = new Storyboard();
myStoryboard.Children.Remove(myDoubleAnimation);
myStoryboard.Stop(this);
I am not able to stop the animation for image button.
Please guide me for above issues.
Regards,
Sachin K
It looks as though you’re stopping a
Storyboardthat wasn’t started. You’re creating an entirely newStoryboardin an attempt to stop the original, but that is nonsensical. Just keep a reference to the original and stop it.