Kyjibo
Kyjibo

Reputation: 71

Storyboard.RepeatBehavior Ineffective

I have a program where I have added a button to toggle weather or not a storyboard I am using should repeat

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;
  }
}

But it isn't working at all. When the animation reaches the end of the first play the Completed event fires(It shouldn't do that) and the animation just stops(That either). I've tried a couple different approaches to no avail and all my searching seems to indicate it's an isolated problem.

What am I doing wrong here?

Here's one of the places where I add some animations to a storyboard. The function this is chopped out of returns the Storyboard s which I then make a child of GlobalStoryboard. I already tried passing GlobalStoryboard to the function and adding the animations directly to it to remove the intermediary storyboard. It did not fix the problem.

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;
}

Upvotes: 2

Views: 3567

Answers (1)

Kyjibo
Kyjibo

Reputation: 71

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.

Upvotes: 1

Related Questions