tailieunhanh - Foundation Silverlight 3 Animation- P5

Foundation Silverlight 3 Animation- P5: Silverlight has really come a long way since I started using it. It’s kind of interesting to look back a mere two years (roughly) and think about how the workflow has changed. Of even more interest is the staggering speed at which new features are being added. In the time I’ve been using Silverlight, it has grown from a somewhat limited toolset to an ever-more-impressive technology that has really started to come into its own. | STORYBOARDS AND ANIMATIONS 6. Add the animation to the storyboard and the storyboard to the LayoutRoot object Anim MoveRight MoveRight 7. All that s left is to add an event listener and an associated event handler. Add the event listener at the bottom of the MainPage constructor. 8. If you are using the method described earlier Visual Studio will create the event handler function for you. All you need to do is add the code that calls the storyboard private void Rectangle_MouseEnter object sender MouseEventArgs e 9. Compile and run the project and place the pointer over the rectangle. The MoveRight storyboard will play moving the rectangle 150 pixels to the right. If you wanted to make the rectangle move at an angle it would be as simple as adding a second animation that changes the Y transform of the object. 10. Add the following code to the project just after Anim . Notice that the new animation s name is yAnim and the TargetProperty has been adjusted to affect the Y transform of the Rectangle object. DoubleAnimationUsingKeyFrames YAnim new DoubleAnimationllsingKeyFrames YAnim Rectangle new PropertyPath . 3 . new TimeSpan o 0 0 SplineDoubleKeyFrame SKeyFramel new SplineDoubleKeyFrame 150 SKeyFramel YAnim Use F5 to compile and run the program again. With the second animation in place the rectangle now moves down and to the right holding the position at the end of the storyboard. Remember that the FillBehavior on storyboards is set to HoldEnd meaning that the storyboard will stay at its last frame when it has finished playing through. If you would like to change the FillBehavior for a storyboard you