1

我有一个程序,我在其中添加了一个按钮来切换天气,或者我正在使用的故事板不应该重复

private void Repeat_Click(object sender, RoutedEventArgs e)
{
  if (globalStoryboard.Children.Count != 0)
  {
    if (globalStoryboard.RepeatBehavior == RepeatBehavior.Forever)
      globalStoryboard.RepeatBehavior = new RepeatBehavior(1.0);
    else
      globalStoryboard.RepeatBehavior = RepeatBehavior.Forever;
  }
}

但它根本不起作用。当动画到达第一次播放结束时, Completed 事件会触发(它不应该这样做)并且动画会停止(或者)。我尝试了几种不同的方法都无济于事,我所有的搜索似乎都表明这是一个孤立的问题。

我在这里做错了什么?

这是我在情节提要中添加一些动画的地方之一。被切掉的函数返回 Storyboard s,然后我将其作为 GlobalStoryboard 的子级。我已经尝试将 GlobalStoryboard 传递给函数并将动画直接添加到它以删除中间故事板。它没有解决问题。

double last = ((data[0] - min) / delta) * angle;
for (double k = 1.001; k < data.Count; k++)
{
  double val = ((data[(int)k] - min) / delta) * angle;
  DoubleAnimation doubleAnimation = new DoubleAnimation();
  doubleAnimation.From = last;
  doubleAnimation.To = val;
  doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
  doubleAnimation.BeginTime = TimeSpan.FromSeconds(k - 1);
  s.Children.Add(doubleAnimation);
  Storyboard.SetTargetName(doubleAnimation, "AxisRotation" + index);
  Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Angle"));
  last = val;
}
4

1 回答 1

0

LPL was correct, when a storyboard is animating it is frozen to prevent interference. I just made the repeat button bind to a Boolean and made the completed event play the storyboard again if it was true.

于 2013-12-16T15:57:51.510 回答