A simple example of WPF Animation

Source: Internet
Author: User

I believe many new people are very interested in WPF animation, but do not know where to start. Here, I will give you a brief introduction to a WPF animation through a few simple examples.

First, you must reference the namespace:

 
UsingSystem. Windows. Media. animation;

 

Create a button in the form:

Grid grid =NewGrid ();//Create a grid layout containerThis. Content =GRID; button mybutton=NewButton (); mybutton. Content="Click me!";//Create buttonMybutton. width =60; Mybutton. Height=30;Mybutton. Click + = mybutton_click;
Grid. Children. Add (mybutton );

Button click event:

Button mybutton =(Button) sender; doubleanimation myani = New Doubleanimation (); //  Instantiate a doubleaninmation object Myani. From = mybutton. width; //  Start Value Myani. To = mybutton. Width + 100 ; //  End value Myani. Duration = timespan. fromseconds ( 3 ); //  Time used Storyboard. settarget (myani, mybutton );//  Set application objects Storyboard. settargetproperty (myani, New Propertypath ( "  Width  " )); //  Set Application dependency attributes Storyboard S = New Storyboard (); //  Instantiate a storyboard S. Children. Add (myani ); //  Add previous animations S. Begin (); // Start story Edition 

 

Now you can run it and find that the width of the button is increased by 100 within 2 seconds.

Now, a simple animation is complete. Of course, you can also process the completed attribute of story and create an animation to restore the original state. You only need to ignore the to attribute:

Clockgroup = (clockgroup) sender; // gets the current clockgroup object
Doubleanimation mys = (doubleanimation) clockgroup. Children [0]. Timeline); // gets the current doubleanimation object
Button mybutton = (button) storyboard. gettarget (MYS); // get the current Button Object
Doubleanimation myani = new doubleanimation (); // instantiate a doubleaninmation object
Myani. From = mybutton. width; // start value
// Ignore the end value
Myani. Duration = timespan. fromseconds (1); // time used
Storyboard. settarget (myani, mybutton); // sets the object of the application.
Storyboard. settargetproperty (myani, new propertypath ("width"); // you can specify the dependency attribute of an application.
Storyboard S = new storyboard (); // instantiate a storyboard
S. Children. Add (myani); // Add the previous Animation
S. Begin (); // starts the Story version.

How is it? Is it easy? In addition to doubleanimation animations, there are 42 animations, including coloranimation and byteanimation. Some of them are the same as doubleanimation, so I will not discuss them here.

 

I am also a newbie, and everyone is learning together.

 

Appendix: https://skydrive.live.com/redir.aspx? Cid = f408a3d3df420664 & resid = f408a3d3df420664! 175 & parid = f408a3d3df420664! 109 & authkey =! Ab3d5yx9ltzenxg

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.