0

I'm trying to assign dynamically created storyboards to dynamically created Rectangles. Actually I'm changing their TranlationTransform attributes:

Storyboard s = new Storyboard();

DoubleAnimationUsingKeyFrames translationAnimation1 =
    new DoubleAnimationUsingKeyFrames();

translationAnimation1.KeyFrames.Add(
    new EasingDoubleKeyFrame(TranslationX,
        KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Seconds))));

Storyboard.SetTarget(translationAnimation1, Element);

Storyboard.SetTargetProperty(translationAnimation1,
    new PropertyPath("(UIElement.RenderTransform).
                      (TransformGroup.Children)[3].(TranslateTransform.X)"));

s.Children.Add(translationAnimation1);


DoubleAnimationUsingKeyFrames translationAnimation2 =
    new DoubleAnimationUsingKeyFrames();

translationAnimation2.KeyFrames.Add(new EasingDoubleKeyFrame(TranslationY,
    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Seconds))));

Storyboard.SetTarget(translationAnimation2, Element);

Storyboard.SetTargetProperty(translationAnimation2,
     new PropertyPath("(UIElement.RenderTransform).
                       (TransformGroup.Children)[3].(TranslateTransform.Y)"));

s.Children.Add(translationAnimation2);

And I want to stop it when I clicked on it:

s.Pause();
s = null;

Yes it pauses but it prevents me to change the TranslateTransform attributes and calling Stop() is not good. The question is how I can stop a storyboard when I clicked on it.

Em1
  • 1,077
  • 18
  • 38
Kaan
  • 902
  • 2
  • 16
  • 38
  • Possible duplicate - http://stackoverflow.com/questions/20298/how-to-stop-an-animation-in-c-wpf – Sandeep G B Sep 16 '11 at 06:53
  • I've tried all the answers but not working. I should somehow pause animation and remove the binding between stroyboard and rectangle. – Kaan Sep 16 '11 at 10:57

0 Answers0