如何在mouseover事件中停止DoubleAnimation?

时间:2014-05-01 10:31:19

标签: wpf wpf-controls marquee wpf-animation doubleanimation

我有两个画布和一个名为tbmarquee的文本块,在窗口加载它从上到下动画,但我想停止当我在它上面的mose,当我点击它去链接,怎么办它?

 void Window1_Loaded(object sender, RoutedEventArgs e)
    {
        DoubleAnimation doubleAnimation = new DoubleAnimation();
        doubleAnimation.From = -tbmarquee.ActualHeight;
        doubleAnimation.To = canMain.ActualHeight;
        doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
        doubleAnimation.Duration = new Duration(TimeSpan.Parse("0:0:10"));
        tbmarquee.BeginAnimation(Canvas.TopProperty, doubleAnimation);

    }

1 个答案:

答案 0 :(得分:1)

tbmarquee的鼠标悬停事件处理程序上,再次调用BeginAnimation()并将第二个参数设置为null以停止动画:

tbmarquee.BeginAnimation(Canvas.TopProperty, null);

相关问题:How to stop an animation in C# / WPF?