c# - 如何禁用 WPF 动画

标签 c# wpf

我有这段代码,但不知道如何禁用动画。

有什么线索吗?谢谢!

      #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

最佳答案

如果您对 BeginStop 使用相同 Storyboard 实例,它就会起作用。将 sb 声明为您的类的成员:

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

    ...
}

关于c# - 如何禁用 WPF 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11760733/

相关文章:

c# - WPF - 在处理过程中更新标签内容

c# - 所以我真的不能在服务器端使用 Excel 对象模型吗?

c# - 返回前验证 null 属性

c# - WPF 程序在一台计算机上启动速度超快,但在另一台计算机上启动速度超慢

c# - 如何将此 StringBuilder-to-XML 代码更改为 LINQ-to-XML?

c# - 我无法使用 INotifyPropertyChanged 更新我的值

c# - 将 Zurb Foundation 添加到新的 asp.net webforms 应用程序

wpf - 如何指定 WPF Image 使用的图像缩放算法?

WPF 重用 DataGrid TemplateColumn DataTemplates

c# - 过滤 PropertyGrid 中显示的属性