我有这段代码,但不知道如何禁用动画。
有什么线索吗?谢谢!
#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
最佳答案
如果您对 Begin
和 Stop
使用相同 Storyboard 实例,它就会起作用。将 sb
声明为您的类的成员:
public class MainWindow
{
private Storyboard sb = new Storyboard();
...
}
关于c# - 如何禁用 WPF 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11760733/