我有一个我正在使用情节提要制作动画的图像。我希望能够在情节提要动画完成后更改图像的来源。但是,我不知道如何在 Completed 事件处理程序中访问 Image。如何通过 Storyboard 对象访问图像。
private void AnimateImage() {
Image i = new Image();
//Set name and source of image here
i.RenderTransform = new CompositeTransform();
Duration d = new Duration(TimeSpan.FromSeconds(2));
DoubleAnimation anim1 = new DoubleAnimation();
DoubleAnimation anim2 = new DoubleAnimation();
anim1.Duration = d;
anim2.Duration = d;
Storyboard sb = new Storyboard();
sb.Duration = d;
sb.Children.Add(anim1);
sb.Children.Add(anim2);
Storyboard.SetTarget(anim1, i);
Storyboard.SetTarget(anim2, i);
Storyboard.SetTargetProperty(anim1, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)");
Storyboard.SetTargetProperty(anim2, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");
//Set anim1/anim2 To/From properties
sb.Completed += StoryboardCompleted;
sb.Begin();
}
private void StoryboardCompleted(object sender, object o) {
Storyboard sb = (Storyboard) sender;
//How can I gain access to the Image?
}
我用多个图像多次制作这个动画,所以我不能简单地制作一个成员变量。我需要知道在 Completed 事件中完成了哪个图像。