WPF动画结束时是否会触发任何事件?
问题描述:
WPF动画结束时是否会触发任何事件?
Is there any event that fires when WPF Animation ends?
void HideDefaultScreenImageTimer_Tick(object sender, EventArgs e)
{
HideDefaultScreenImageTimer.Stop();
var doubleAnimation = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.45)));
DefaultScreenImage.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
// I need some event when an animation ENDS and within that event I want to remove
// Image (DefaultScreenImage) from Canvas.
MainCanvas.Children.Remove(DefaultScreenImage);
}
答
是的.
因此您的代码变为:
void HideDefaultScreenImageTimer_Tick(object sender, EventArgs e)
{
HideDefaultScreenImageTimer.Stop();
var doubleAnimation = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.45)));
doubleAnimation.Completed += (sender, eArgs) => MainCanvas.Children.Remove(DefaultScreenImage);
DefaultScreenImage.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
}