There was a baby shoe in the crowd yesterday. How to obtain the UI object that executes the animation in the animation completion event completed.
The completed of animation in WPF itself does not return the UI object that executes the animation, but we can use the attached property storyboard.targetproperty to achieve the desired effect.
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/
Steps:
1 Attach the property record object before performing the animation
DoubleAnimation ani = new DoubleAnimation ();
Ani. from = start;
Ani. to = end;
Ani. Duration = new Duration (Timespan.fromseconds (0.25));
ani.completed + = ani_completed;
/* !!! Attached property Storyboard.target, which specifies the UI object that executes the animation!!! * *
storyboard.settarget (ANI, UIElement);
/* Start animation
/uielement.beginanimation (Canvas.leftproperty, ANI);
2 in the animation of the completed event method to retrieve
If (sender is AnimationClock)
{
animationtimeline timeline = (sender as AnimationClock). Timeline;
/* !!! Retrieving the UI object with additional properties!!! *
/Object UIElement = Storyboard.gettarget (timeline);
}
Comes with a Demo