Part 2: Transformation and keyspline
This section will teach you some advanced blend 2 SP1 technologies: How to Create transformations and perform more control.
To complete this step, you need to install expression blend 2 SP1 or later.
TheCodeDownload from here
- Download and open the project
Use the link above to download the project and open it.
You should see something as shown in.
- Create a new over status
Use the same method in the previous tutorialMouseinteractionCreate a new name in the groupOver.
- ClickAdd statusCreate a new state.
- Rename itOver.
- Change the over status attribute
For the over status, reduce the image size.
- Select the over status, click the image, and change scale transform to X = 0.55, y = 0.55.
- Add mouse entry and remove events
- Click the image to select it. The event bar under the Property panel is displayed.
- In the mouseenter and mouseleave events, enter goover and goleave respectively. (See figure)
This will create two functions in page. XAML. CS to become goover and goleave respectively.
- Add code to page. XAML. CS
To make the status work, you need to add the following code in the goover function, just as we did in the previous tutorial.
Visualstatemanager. gotostate (this, "over", true );
Add the code to the goleave function to return the normal state.
Visualstatusmanager. gotostate (this, "normal", true );
See images.
- Control Transformation
If you runProgram, You will see that all the statuses can work, from normal to over, to click, return over, return normal, and so on. However, all the transformations take place in 0.3 seconds. This is the default value defined for the status group.
To control a single transformation, we need to add...Transform. Let's addOverToClick.
- InOverClick on statusAdd Transform.
It shows you a list of all possible combinations of changes in the group.
- SelectOver-> click. Next new transformation over.
- Change the time0.1.
If you run the program, you will see that when you click, the animation speed will become much faster. This is a powerful feature because it allows you to control any State to make it another state.
(*) Symbol allows you to define a transform to make all (*)ChangeA specified status.
- Each status has a timeline
When we use the stateDurationWhen the option defines the time of each transformation, we do not have the option to defineKeyspline(How to accelerate an animation ). To control the keyspline, we need to open the timeline of the status.
- SetDefault conversion Interval0.
- ClickDelete changesTo removeOver-> clickTransform.
- SelectOverStatus
- ClickShow timelineTo extend the over status timeline
You will seeImageThere is only one elementKeyframe. Now you can create an animation, just like any otherStoryboard.
- Change transform using timeline
Now that you have accessed the timeline, you can control the animation time here.
- To changeTime, DragKeyframeTo the target location. In the example image, the example is a one-second transformation. But a better result would be:0.3 s.
- Modify keyspline
Another advanced application of timeline is that you can changeKeysplineAnd control the slow in/out of each key frame.
- ClickKeyframeAnd changeAttributePanelKeysplineGraph
In this example, we get a more natural animation, instead of a boring start/end.