You may have discovered that no matter what type of animation, the method of use is basically the same. I don't know if you have summed up the rule? When you find the rule, you will find that the rule can be used for the first to sixth, not to lie to you.
To help you find the rule, let's write two more examples today.
I. discreteobjectkeyframe
This is a brief introduction. It is provided to facilitate some large switchover, but it is not omnipotent. Although its target type is object type, the premise is that, like other animations, an animation can only process a certain attribute of an object. Compared with flash, Silverlight is less flexible, but we know that after all, Silverlight was not born for animation purposes. Microsoft launched it for enterprise-level applications. The so-called multimedia support or animation is to provide a better user experience. Do not treat it as a special entertainment.
Well, let's talk about F. Let's start the exercises below. First, you can refer to the following XAML code to complete the foreground layout. Wherever you write it, you can find the grid control as a container. The exercises are also flexible, and I will never have the requirement for hard work.
[HTML]View plaincopyprint?
- <Grid>
- <Rectangle X: Name = "REC" margin = "100,200" loaded = "rec_loaded"/>
- <Grid. Resources>
- <Storyboard X: Name = "STD">
- <Objectanimationusingkeyframes
- Duration = "0: 0"
- Storyboard. targetname = "REC"
- Storyboard. targetproperty = "fill"
- Repeatbehavior = "forever">
- <Discreteobjectkeyframe keytime = "0: 0">
- <Discreteobjectkeyframe. value>
- <Solidcolorbrush color = "blue"/>
- </Discreteobjectkeyframe. value>
- </Discreteobjectkeyframe>
- <Discreteobjectkeyframe keytime = "0: 0">
- <Discreteobjectkeyframe. value>
- <Lineargradientbrush startpoint = "0, 0" endpoint = "1, 1">
- <Gradientstop color = "red" offset = "0"/>
- <Gradientstop color = "yellow" offset = "0.5"/>
- <Gradientstop color = "Purple" offset = "1"/>
- </Lineargradientbrush>
- </Discreteobjectkeyframe. value>
- </Discreteobjectkeyframe>
- <Discreteobjectkeyframe keytime = "0: 0">
- <Discreteobjectkeyframe. value>
- <Radialgradientbrush center = "0.5, 0.5" radiusx = "0.5" radiusy = "0.5">
- <Gradientstop color = "snow" offset = "0"/>
- <Gradientstop color = "green" offset = "1"/>
- </Radialgradientbrush>
- </Discreteobjectkeyframe. value>
- </Discreteobjectkeyframe>
- </Objectanimationusingkeyframes>
- </Storyboard>
- </Grid. Resources>
- </GRID>
In the code above, we define a rec_loaded event handler to start the animation. Therefore, right-click rec_loaded in the code above, select "navigation to event handler" from the pop-up menu, and a event processing method rec_loaded is generated. Then, we start playing the animation here.
[CSHARP]View plaincopyprint?
- Private void rec_loaded (Object sender, routedeventargs E)
- {
- This. STD. Begin ();
- }
Now, please debug and run it.
2. linearpointkeyframe
This is something that everyone must be familiar with. It refers to animation between two points. In the previous example, it is a key frame animation, that is, animation can be generated between N points. When using XAML, it is a child element of pointanimationusingkeyframes.
Refer to the following XAML code to build the UI.
[HTML]View plaincopyprint?
- <Grid>
- <Ellipse X: Name = "ell" width = "400" Height = "400" loaded = "ell_loaded">
- <Ellipse. Fill>
- <Radialgradientbrush center = "0, 0.5" radiusx = "1" radiusy = "0.5">
- <Gradientstop color = "gold" offset = "0"/>
- <Gradientstop color = "red" offset = "1"/>
- </Radialgradientbrush>
- </Ellipse. Fill>
- </Ellipse>
- <Grid. Resources>
- <Storyboard X: Name = "STD">
- <Pointanimationusingkeyframes
- Duration = "0: 12"
- Storyboard. targetname = "ell"
- Storyboard. targetproperty = "(ellipse. Fill). (radialgradientbrush. Center )"
- Repeatbehavior = "forever">
- <Linearpointkeyframe keytime = "" value = "0.5, 1"/>
- <Linearpointkeyframe keytime = "0: 0" value = "1, 0.5"/>
- <Linearpointkeyframe keytime = "" value = "0.5, 0"/>
- <Linearpointkeyframe keytime = "0: 0" value = "0, 0.5"/>
- </Pointanimationusingkeyframes>
- </Storyboard>
- </Grid. Resources>
- </GRID>
Do not forget to start the animation.
[CSHARP]View plaincopyprint?
- Private void ell_loaded (Object sender, routedeventargs E)
- {
- STD. Begin ();
- }
Okay. Let's see how it works.
I don't know how you feel through practice. If you have a solid foundation in WPF, I believe you don't have to understand these examples at all. Of course, if you are a beginner, don't be scared by these things. If you really want to learn something, even if you don't understand something in theory (in fact, few people actually understand things in theory, the key is more hands-on and more exercises. You can simply wear your clothes. No one says you have to know how to make them. Is that true? If you don't understand how the farmer's uncle planted the dishes, won't you eat them?