Search Chirayu Software Solutions Blog

Tuesday, September 11, 2012

Rotate Rectangle Animation WPF

Step 1: Place a button and shape rectangle on the form. (Button is not needed. I use it just for raising an event.)
Step 2: Add the following code in the button click event:
Note: Do not forget to import System.Windows.Media.Animation namespace.
DoubleAnimation da = new DoubleAnimation();
da.From = 0;
da.To = 360;
da.Duration = new Duration(TimeSpan.FromSeconds(3));
da.RepeatBehavior = RepeatBehavior.Forever;
RotateTransform rt = new RotateTransform();
rectangle1.RenderTransform = rt;
rt.BeginAnimation(RotateTransform.AngleProperty, da);
Step 3: Execute and enjoy. You can see a rectangle rotating 360 degrees continuously
Post a Comment