我正在尝试将动态创建的故事板分配给动态创建的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()
并不好。问题是我点击它时如何停止故事板。