我能够从代码下方为图像按钮提供动画。
this.RegisterName(image1.Name, image1);
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 1.0;
myDoubleAnimation.To = 0.0;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.25));
myDoubleAnimation.AutoReverse = true;
myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
myStoryboard = new Storyboard();
myStoryboard.Children.Add(myDoubleAnimation);
Storyboard.SetTargetName(myDoubleAnimation, image1.Name);
Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Image.OpacityProperty));
myStoryboard.Begin(this);
现在我需要停止动画。
以下是示例代码。
TimeSpan? ts = new TimeSpan(0,0,2);
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 1.0;
myDoubleAnimation.To = 0.0;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));
myStoryboard.BeginTime = ts;
myDoubleAnimation.AutoReverse = true;
myStoryboard = new Storyboard();
myStoryboard.Children.Remove(myDoubleAnimation);
myStoryboard.Stop(this);
我无法停止图像按钮的动画。 请指导我以上问题。
此致
Sachin K
答案 0 :(得分:1)
看起来你正在停止一个未启动的Storyboard
。你正在创建一个全新的Storyboard
以试图阻止原作,但这是荒谬的。只需保留对原始文件的引用并停止 it 。