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