【发布时间】:2014-04-16 20:09:53
【问题描述】:
我正在使用以下代码来启动/维护故事板动画:
private Storyboard storyboard = null;
private DoubleAnimation leftArrow = null;
private DoubleAnimation rightArrow = null;
public void AnimateArrows(bool left = true, bool right = true)
{
if (storyboard != null) storyboard.Stop();
else storyboard = new Storyboard();
storyboard.Children.Clear();
if (left)
{
leftArrow = new DoubleAnimation();
leftArrow.From = 0.5;
leftArrow.To = 1;
leftArrow.Duration = TimeSpan.FromSeconds(0.3);
leftArrow.AutoReverse = true;
leftArrow.RepeatBehavior = RepeatBehavior.Forever;
Storyboard.SetTargetProperty(leftArrow, new PropertyPath(Image.OpacityProperty));
Storyboard.SetTargetName(leftArrow, btnLeftAS.Name);
storyboard.Children.Add(leftArrow);
}
else
{
storyboard.Remove(btnLeftAS);
}
if (right)
{
rightArrow = new DoubleAnimation();
rightArrow.From = 0.5;
rightArrow.To = 1;
rightArrow.Duration = TimeSpan.FromSeconds(0.3);
rightArrow.AutoReverse = true;
rightArrow.RepeatBehavior = RepeatBehavior.Forever;
Storyboard.SetTargetName(rightArrow, btnRightAS.Name);
Storyboard.SetTargetProperty(rightArrow, new PropertyPath(Image.OpacityProperty));
storyboard.Children.Add(rightArrow);
}
else
{
storyboard.Remove(btnRightAS);
}
storyboard.Begin(this, true);
}
我需要能够在任何给定点禁用箭头/元素的动画,同时保持其他动画。
我正在尝试暂停其中一个箭头的动画,如下所示:
private void btnLeftAS_MouseEnter(object sender, MouseEventArgs e)
{
AnimateArrows(false, true);
((Image)sender).Opacity = 1;
}
但是,在调用这个之后,动画会继续。我已经尝试了http://msdn.microsoft.com/en-us/library/aa970493(v=vs.110).aspx中列出的每个选项
我在这里缺少什么?如何停止一个元素的动画?
【问题讨论】:
标签: c# wpf animation storyboard