Msdn tutorial short film WPF 16 (Path)

Source: Internet
Author: User
Animation path-Path

The path has a date attribute, which is used to obtain or set the geometry of the specified shape.

So we draw a circle and an elliptical path. The circle moves on the elliptical path. First we draw a circle.

<Ellipse X: Name ="E1"Stroke ="Black"Width ="50"Height ="50"Fill ="Red"Margin ="0, 0, 228,211"> </Ellipse>

Draw a path

<Path X: Name ="P1"Stroke ="Blue"> <Path. Data> <ellipsegeometry X: Name ="Eg1"Center ="120,100"Radiusx ="100"Radiusy ="50"> </Ellipsegeometry> </path. Data> </path>
Here, the ellipsegeometry in this path is named eg1, which will be used later. Now we can perform rendertransform On This ellipse, as shown below: Code .
<Ellipse X: Name ="E1"Stroke ="Black"Width ="50"Height ="50"Fill ="Red"Margin ="0, 0, 228,211">
 
<Ellipse. rendertransform>
 
<Transformgroup>
<Translatetransform x ="-25"Y ="-15"/>
 
<Matrixtransform X: Name ="M1"/>
 
</Transformgroup>
 
</Ellipse. rendertransform>
<Ellipse. triggers>
 
<Eventtrigger routedevent ="Page. Loaded">
 
<Beginstoryboard>
 
<Storyboard X: Name ="S1"Repeatbehavior ="Forever">
<Matrixanimationusingpath X: Name ="Ma1"
 
Storyboard. targetname ="M1"
 
Storyboard. targetproperty ="Matrix"
Duration ="0: 0: 5"/>
 
</Storyboard>
 
</Beginstoryboard>
 
</Eventtrigger>
</Ellipse. triggers>
 
</Ellipse>

Here we use matrixanimationusingpath in storyboard,

You can use pathgeometry to generate an animation value to animation the value of the matrix attribute. This animation can be used to move a visual object along a path.

Matrixanimationusingpath is bound to M1 and its attribute is matrix. M1 is matrixtransform, which is

Creates an arbitrary ry matrix transformation to operate objects or coordinate systems in a two-dimensional plane.

<Translatetransform x ="-25"Y ="-15"/> Is to adjust the degree of translation for the circle to rotate along the elliptical path.

Translatetransform: You can change the origin of the coordinate system by making the translation of the transformation matrix of graphics left by the specified translation.

We also need to use a button to load and start this path.

Private VoidButton#click (ObjectSender, routedeventargs e) {pathgeometry =NewPathgeometry (); pathgeometry. addgeometry (eg1); ma1.pathgeometry = pathgeometry; s1.begin (E1 );}

Press F5 for debugging.

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.