Windows Phone development (36): animated doubleanimation to: http://blog.csdn.net/tcjiaan/article/details/7521388

Source: Internet
Author: User

Starting from this section, we will discuss an interesting topic-animation.

When you see the word "Animation", you must think of flash. After all, a very important framework of the WP application is Silverlight, which has also played many advantages of Silverlight. Many people may say that, silverlight is similar to flash. When you have a deep understanding of Silverlight, you will find that, in fact, Silverlight is more focused on data processing and enterprise-level applications.

 

Well, f doesn't talk much about it. Let's start to blow our cowhide. Before we blow cowhide, we should know where the cowhide comes from. Before talking about animation, let's first think about what is a storyboard? How do you think this is a good translation? It's a demo board. msdn translates it like this. I 'd like to say it's an intuitive concept. I don't know if you 've ever played flash, there is a "Frame Panel" in flash. Yes, in fact, this demonstration board has a very serious similarity with the frame panel.

In this case, let's take a look at the fact that. NET is very powerful. Therefore, open express blend to see a graphical Demo Board, so that everyone will understand it better.

 

In this way, the storyboard is derived from timeline, and the timeline is crucial in the animation. We all know that the so-called animation will be "dynamic ", it is precisely because of the time difference that the concept of "frame" can be understood by everyone. It is only worth mentioning that you have a tacit understanding with her.

 

A storyboard can contain more than n sub-animation timelines. Today we will first learn about a relatively simple one. doubleanimation is used to animation two double values within a certain period of time, such as the width of the visualization element, height, transparency, etc.

 

Severe warning: not all attributes can be animated. The attribute to be animated must be a dependency attribute.

 

Well, there's a lot to talk about in theory. It's easy for people to get confused. Let's just do it.

Next we will do a drill.

 

Step 1: Create a WP application project, with 35 words omitted here.

Step 2: Add a rectangle and two buttons to the page. The rectangle is "Mouse" and used for animation experiments. For the two buttons, one is playing an animation, one is to stop the animation. How to arrange the interface, as you like.

[HTML]View plaincopyprint?

  1. <! -- Contentpanel-place other content here -->
  2. <Grid X: Name = "contentpanel" grid. Row = "1" margin = "12,0, 12,0">
  3. <Grid. rowdefinitions>
  4. <Rowdefinition Height = "*"/>
  5. <Rowdefinition Height = "Auto"/>
  6. </Grid. rowdefinitions>
  7. <Rectangle X: Name = "REC"
  8. Grid. Row = "0"
  9. Margin = "100"
  10. Fill = "yellow"/>
  11. <Stackpanel grid. Row = "1" orientation = "horizontal">
  12. <Button content = "play" Click = "play_click"/>
  13. <Button content = "stop" Click = "stop_click"/>
  14. </Stackpanel>
  15. </GRID>

 

Step 3: Add a storyboard to the grid named contentpanel as a resource, declare a doubleanimation in it, and change the transparency of the rectangle to 0 in five seconds, even if the rectangle produces an animation effect that fades out.

Storyboard. the targetname additional attribute specifies the name of the object to be animated. If you want to destroy the object, write its name. storyboard. targetproperty is an attribute for animation processing. We need to over-animation transparency, so the opacity attribute is used here. Duration is the animation duration. It takes 5 seconds.

[HTML]View plaincopyprint?

  1. <Grid. Resources>
  2. <Storyboard X: Name = "STD">
  3. <Doubleanimation
  4. Duration = "0: 5"
  5. Storyboard. targetname = "REC"
  6. Storyboard. targetproperty = "opacity"
  7. To = "0"/>
  8. </Storyboard>
  9. </Grid. Resources>

Step 4: process the click events of the two buttons respectively, and call the begin and stop methods of the storyboard to control the playback and stop of the animation.

[CSHARP]View plaincopyprint?

  1. Private void play_click (Object sender, routedeventargs E)
  2. {
  3. This. STD. Begin ();
  4. }
  5. Private void stop_click (Object sender, routedeventargs E)
  6. {
  7. This. STD. Stop ();
  8. }

 

Okay. Run it now.

 

 

 

 

Isn't it good enough? Let's do another one. How can we change the width of an elliptic from 20 to 420 in 3 seconds.

View the XAML code.

[HTML]View plaincopyprint?

  1. <Grid X: Name = "contentpanel" grid. Row = "1" margin = "12,0, 12,0">
  2. <Grid. rowdefinitions>
  3. <Rowdefinition/>
  4. <Rowdefinition Height = "Auto"/>
  5. </Grid. rowdefinitions>
  6. <Ellipse grid. Row = "0" Height = "325" name = "ell" width = "15" fill = "darkorange"/>
  7. <Stackpanel grid. Row = "1" orientation = "horizontal">
  8. <Button content = "play" Click = "onplay"/>
  9. <Button content = "stop" Click = "onstop"/>
  10. </Stackpanel>
  11. <Grid. Resources>
  12. <Storyboard X: Name = "STD">
  13. <Doubleanimation duration = "0: 0"
  14. Storyboard. targetname = "ell"
  15. Storyboard. targetproperty = "width"
  16. From = "20"
  17. To = "420"/>
  18. </Storyboard>
  19. </Grid. Resources>
  20. </GRID>

 

Background code:

 

[CSHARP]View plaincopyprint?

  1. Private void onplay (Object sender, routedeventargs E)
  2. {
  3. This. STD. Begin ();
  4. }
  5. Private void onstop (Object sender, routedeventargs E)
  6. {
  7. This. STD. Stop ();
  8. }

 

Check the running effect.

Related Article

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.