必须非常简单,但已经花了我几十分钟来解决。这就是为什么要问。
// start animation like this
var storyboard = new Storyboard();
...
storyboard.Completed += storyboard_Completed;
storyboard.Begin(control); // << "control"
static void storyboard_Completed(object sender, EventArgs e)
{
var storyboard = sender as Storyboard;
...
// how to get "control" here?
}
我可以使用属性或者为故事板(附加属性?)创建Tag
种。但对于如此明显的任务而言,它不会那么复杂。
答案 0 :(得分:2)
Completed
事件继承自Timeline.Completed
Event。您可以看到它使用标准EventArgs
对象,因此很明显,它无法存储对Animation
中可能使用的任何控件的引用。
您最简单的方法是获取对应用Animation
的控件的引用,您可以在类中定义私有成员变量:
private UIElement animatedContol = null;
...
// start animation like this
var storyboard = new Storyboard();
...
storyboard.Completed += storyboard_Completed;
storyboard.Begin(control);
animatedContol = control;
...
static void storyboard_Completed(object sender, EventArgs e)
{
var storyboard = sender as Storyboard;
...
// do something with animatedContol here
}