Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)"
From="0"
To="360"
Duration="0:0:0.5"
RepeatBehavior="4x" />
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!!!
PeterPosted Aug 10, 2009, 4:55 PM
But that's OK - I rewrote the app from scratch and figured out a solution on my own - it's based on the recognition that RotateTransform is not a direct property of a TextBlock. To make the rotation angle accessible, first do this in the XAML:
Then in the code-behind, you can do it this . . .
Storyboard sb = new Storyboard();
// Create a DoubleAnimation to animate the angle . . .
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 0;
myDoubleAnimation.To = 180;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(2500));
Storyboard.SetTargetName(myDoubleAnimation, "rtAngle");
PropertyPath PropP = new PropertyPath(RotateTransform.AngleProperty);
Storyboard.SetTargetProperty(myDoubleAnimation, PropP);
sb.Children.Add(myDoubleAnimation);
sb.Begin(this.textBlock1);
Note that my original code also had an error in the invocation of the animation, now fixed.
Sanjay ChauhanPosted Aug 10, 2009, 1:58 AM
Take the reference of this article
http://www.galasoft.ch/mydotnet/articles/article-2006102701.aspx