c# - WPF 动画结束时是否会触发任何事件?

标签 c# wpf xaml doubleanimation

WPF 动画结束时是否会触发任何事件?

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);
}

最佳答案

是的。

The Completed Event (MSDN) .


所以你的代码变成:

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);
}

关于c# - WPF 动画结束时是否会触发任何事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9194147/

相关文章:

c# - 在 WP8.1 中缩放图像

c# - 如何突出显示选定的html内容作为摘要c#,jquery,javascript,ajax

WPF WriteableBitmap 透明度问题

c# - 如何覆盖 ViewModel DataContext 以便我可以绑定(bind)到 View (Mvvm-Light) 中的对象?

.net - 在 xaml 中为组合框设置选定值时出现问题

c# - 以正确的 WCF 格式返回 JSONP

c# - 未检测到已安装的组件。元素已经是另一个元素的子元素

c# - 使用 Array.Sort() 对元素进行排序而不是对第一个元素进行排序

C#编译器和局部变量的缓存

c# - 使用 MVVM Light 时如何将弹出窗口绑定(bind)到 ViewModel - BindingExpression 路径错误