如何停止故事板像暂停

时间:2011-09-16 06:26:06

标签: c# wpf animation

我正在尝试将动态创建的故事板分配给动态创建的Rectangle。实际上我正在改变他们的TranlationTransform属性:

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);

我想在点击它时停止它:

s.Pause();
s = null;

是的它会暂停,但它会阻止我更改TranslateTransform属性,并且调用Stop()并不好。问题是我点击它时如何停止故事板。

0 个答案:

没有答案