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

1 comment:

Naresh Ravlani said...

hey this is preety simple example for expression blend users.

If you want to see some really intresting examples , I recommend you to visit Mike Taulty's blog or BLEND BIT series by Mike Taulty.