DCSIMG
WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.) - Maxim

WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Recently I required to create some simple control that shows 'wait process' (like this image in Vista). MS Blend allows you to create cool animated control in one minute or even less.
I want to show how to create very simple continuous animation and some tips in quick animation creation.

Minimum requirements before you'll continue: this post wasn't written as 'Kit for Beginners', means that you must have a basic knowledge/experience in MS Blend application.

 

Open MS Blend (ver. can be 1+ or 2+) and create new WPF (EXE) project.

Draw two circles (in main window).

Select 'Ellipse' shape and hold 'Shift' key to draw perfect circles (the radius of small circle is about ~60% radius of big).

image  image image 

Align small circle in center of big.

Select both circles and do right-click, when click on 'Horizontal Centers' and 'Vertical Centers' to align circles under 'Align' menu.

image image

Combine circles into one shape (ring like donates).

Select both circles and press on right mouse key. Click on 'Exclude Overlap' under 'Combine' menu.

image image

Fill background color.

Use gradient brush with preferred colors. One side can be darker, lighter side can be semitransparent.

image image image

Fill outline (stroke) color.

Use solid or gradient brush (can be semitransparent).

image image

Convert shape (ring) into user control.

Right-Click on shape and click on 'Make Control...'

image image

Blend  generates new user control from defined shape (and replaces shape path in 'Window1' with instance of 'ucWaiting').

image image 
     (appeared in 'Window1.xaml')

Rebuild project before you'll proceed to next paragraphs. 

Create simple rotation animation.

Because the control must be with continues animation from the moment when its loading event is fired, I suggest to create new stroryboard from adding new event in triggers panel.

Click on '+ Event' button in 'Triggers' panel, Blend will add default event 'Loaded' (fired when control is loaded in parent's visual container).
Click on '+' and 'OK' in message box that asks you if you want to create new stroryboard (animation).

image image

These actions are leading to creation of new timeline with storyboard (animation) named 'OnLoaded1'.
The Blend is switched into recording mode, turn it off by clicking on red circle (see marks):

image 

Save current shape position in timeline by recording new keyframe. Zoom-In the timeline and move it position of 0.5 seconds. Select shape (ring) and click on red circle to start recording.

image image

Rotate shape 360 degrees (hold 'Shift' button for 45 deg. rotation for each movement). After one round is completed, turn-off the recording. You can preview animation by pressing 'play' button.

image image

Storyboard contains animation with two keyframes, animation makes simple rotation of the shape. Animation will be started when 'Load' event is fired.


Continuous Animation

Last step in animation is to set continuous rotation.

Expand 'path' object in objects and timeline tree and expand 'RenderTransform' and 'Rotation' animation. Do right-click on 'Angle' item and click on 'Edit Repeat Count' in context-menu.
When 'Edit Repeat' window is opened click on marked button 'Set to Forever', click on 'OK' to close the dialog.

image image

The animation will be played forever.

Adjust size of control in main window and test project.

Set control's size 24x24 and press <F5> key.

image

Now it is ready!

>> Of course you can improve this control by adding new functionality, properties (like boolean 'EnableAnimation' or 'ContinuouseAnimation'), by defining more sexy design of shape(s) and/or colors.

PS

Additional tips for animations.


This sub-menu allows to create animations in easy way:

image
Many beginners unfamiliar with these options:

[Duplicate] - duplicates selected animation, very useful in case you want to save extra work by duplication existing animation

[Reverse] - reverses keyframes, very useful in case you want to switch keyframes or to create duplicated animation with reversed keyframes, for example: one animation is used to show some GUI element, another is used to hide this element; you can create one animation for showing of element and another animation will be duplicate (copy) with reversed keyframes.


Hope this post was helpful ;-)

Technorati Tags: ,,,

Comments

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Saturday, March 08, 2008 2:53 PM by Miki Lior

great stuff! is there a way to do it on WinForms?

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Saturday, March 08, 2008 3:30 PM by Maxim

1. Yes, use 'Paint' method of control, implement timer to redraw shape on each tick. The questions are: How much time will take the creation of control? Does it worth? Will it be with smooth and light animation for large sizes?

2. Anyway, this post is tagged 'WPF' and shows how to build such control in couple of clicks.

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Wednesday, September 10, 2008 6:45 PM by wilco

Great post! How do I add a property or method to start/stop the animation?

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Thursday, December 04, 2008 6:47 PM by Dave

What would you do to add custom properties to this, like start/stop animation?

I'm with wilco.

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Sunday, December 07, 2008 9:24 AM by Maxim

If you've created a "UserControl" you can write properties with "get/set" in ".cs" file that comes with ".xaml" file of this "UserControl", like "(bool)IsAnimationEnabled" [TRUE]="StartAnimation", [FALSE]="StopAnimation"; and/or you can write public methods to start/stop the animation. Before that set name of animation in properties grid in Blend, so you can call to "StartAnimation(...)" in code.

There's additional way to create properties in ".xaml" file (allows writing C# code in XAML):

<x:Code>

<![CDATA[

// all written code will be added to generated source file

private bool animEnabled;

public bool IsAnimationEnabled

{

get { return animEnabled; }

set

{

if(animEnabled == value) return;

animEnabled = value;

if(value)

StartAnimation(animCircle);

else

animCircle.Stop();

}

}

]]>

</x:Code>

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Wednesday, February 18, 2009 9:00 AM by Bhagaban

The example is simple but it makes sense...

Very good...I got an good intro to this..

# WPF: Animated Wait Control в Expression Blend 3

Friday, July 24, 2009 6:28 PM by Denis Gladkikh

В WPF мне понадобилось (захотелось) сделать контрол, который бы показывал процес

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Wednesday, September 30, 2009 11:39 AM by Tom

Please give us the XAML code for this! :)

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Wednesday, September 30, 2009 10:28 PM by Sean

Yes, I would love to see the XAML code that Blend generates for this.  I did something similar by hand using one ellipse with a gradient filled stroke.  But, I'm interested in seeing how exclude overlap looks.

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Friday, October 30, 2009 5:33 PM by Scott

Thanks so much for this!  I've never used Blend before but thanks to your post I was able to create my own progress indicator in only a few minutes!

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Monday, November 02, 2009 10:48 PM by Maxim

Welcome :)

I'm planning more simple and useful examples.

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Friday, October 29, 2010 4:44 PM by Boris

Thanks

# WPF Wait / Busy Animation

Friday, April 01, 2011 5:48 PM by TechNewLogic

WPF Wait / Busy Animation

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Сум бил на интернет се обидуваат да најдат идеи за тоа како да се добие мојот личен блог сајтот кодиран, вашиот стил и присутна тема се прекрасни. Дали сте го кодот себе или да го регрутира coder да се направи тоа за вас лично?

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Friday, April 29, 2011 8:47 PM by tauqir

Really very good Example. Presented in very simple way.

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Thursday, May 12, 2011 6:26 AM by DancingKim

Hi, i'm a professional dancer. i need to make a showreel regarding my promotions. I also desire to use some animation. Can someone suggest me the best animation studio, but not really very expensive? I'm here for 3 months for a tour.    

Love    

Kim.

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Thursday, May 19, 2011 3:54 AM by DevenderYadav

Hi... i'm an aspiring animator and i want to know the number of major animation studios within Delhi, India area.... i would really appreciate ur support.    

kind regards    

Devender.    

P.S. I didn't find any sort of category for employment in blogs.microsoft.co.il that's why i has written this question in this category. Hope it's ok.

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Wednesday, May 25, 2011 6:35 PM by RiyaButler

Good day,  

I am an American. I wish to Build an Animation Studio in India. At present i'm browsing for animators. I decided on India because it is more cost-effective than U.S. I wish to know the processes for starting a business in India, specially an animation studio.  

Could you fellas please guide me out?

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Monday, May 30, 2011 1:51 AM by RiyaButler

Hello there Buddies,  

Just joined the gang. Hope to have very good time here.  

luv    

Riya

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Sunday, June 05, 2011 2:52 PM by Вибропогружатель

Я конечно, мало, что смыслю в посте, но постараюсь осилить.

# re: WPF - Code Example: Simple Wait-Progress Control (continuous animation, e.g.)

Saturday, July 02, 2011 10:43 AM by GraifeWeiters

Hi Potterheads, OMG I am so excited about the new movie. I can barel wait. So my question to all you potterheads is what are you going to dress up like? I am basically settled on what I am going to dress up like but can't settle on the wand. Pleaseeeeeeeeeeeeeeeeeeeeeeeee help me choose out of these three -  

Lord Voldermort Wand

cgi.ebay.com/.../eBayISAPI.dll

Dumbeldore's Elder Wand

cgi.ebay.com/.../eBayISAPI.dll

Harry Potter's Wand

cgi.ebay.com/.../eBayISAPI.dll

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: