Peter

Peter

  • NA
  • 20
  • 0

Why doesn't this rotate? (WPF, Storyboard)

Aug 8 2009 6:26 PM
I'm trying to learn how to implement Storyboards in the code-behind.   I have a simple rotation of some label text that works fine in XAML . . .

    <Storyboard  x:Key="StoryboardRotation">
                      <DoubleAnimation
                      Storyboard.TargetName="lblHello"
                      Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)"
                      From="0"
                      To="360"
                      Duration="0:0:0.5"
                      RepeatBehavior="4x" />
    </Storyboard>


But when I try to implement it in a button handler in the code-behind it doesn't rotate (nothing seems to happen) . . .

            Storyboard sb = new Storyboard();

            DoubleAnimation da_AngleAnimation
               = new DoubleAnimation();

            da_AngleAnimation.From = 360;
            da_AngleAnimation.To = 0;
            da_AngleAnimation.Duration
              = new Duration(new TimeSpan(0, 0, 0, 0, 500));
            da_AngleAnimation.RepeatBehavior = new RepeatBehavior(4);

            PropertyPath PropP = new PropertyPath(RotateTransform.AngleProperty);

            Storyboard.SetTargetName(da_AngleAnimation, lblHello.Name);
            Storyboard.SetTargetProperty(da_AngleAnimation,PropP);

            sb.Children.Add(da_AngleAnimation);

            this.BeginStoryboard(sb);



What am I doing wrong?   Thanks in advance!!!

Answers (2)