2

我有这段代码,无法弄清楚如何禁用动画。

有什么线索吗?谢谢!

      #region Blinking Animation
            Storyboard sb = new Storyboard();
            if (IsImageBlinking)
            {
                DoubleAnimation da = new DoubleAnimation();

                da.From = 1.0;
                da.To = 0.0;
                da.RepeatBehavior = RepeatBehavior.Forever;
                da.AutoReverse = true;


                sb.Children.Add(da);
                Storyboard.SetTargetProperty(da, new PropertyPath("(Image.Opacity)"));
                Storyboard.SetTarget(da, image1);
                sb.Begin();
            }
            else // This code doesn't disable the animation :(
            {
//!!!! Here I need to disable the animation.  
                sb.Stop();
                sb.Children.Clear();
            }

            #endregion
4

2 回答 2

5

如果您对 和 使用相同的Storyboard实例,它就可以工作。声明为您的班级成员:BeginStopsb

public class MainWindow
{
    private Storyboard sb = new Storyboard();

    ...
}
于 2012-08-01T14:01:59.190 回答
2

您是否尝试过使用sb.BeginAnimation(Image.OpacityProperty, null);而不是sb.stop()

于 2013-03-13T11:03:25.670 回答