[Aaronyang] Write to own WPF4.5 note 18[geometry *geometry Illustrated]

Source: Internet
Author: User
Tags custom graphics

Why should you master it? Because the WPF 3D knowledge is much more geometry than it is, I want to learn it systematically.

--Learn to populate the Data property of path with geometry.

The graph can be converted to a path, the value of path, of course you can also directly use the rectangle control

Path of course has the advantage of the path, I in Blend5 public Class 3 demonstrates a lot of ways to use, such as motion path, layout path, clipping path, etc.

Of course, in blend, you can quickly become a path.

The converted code is as follows:

 <  path  data  = "m2.5,2.5 l47.5,2.5 l47.5,97.5 l2.5,97.5 z"   Fill  = "Yellow"   Height  = "  Canvas.Left  = "94"   Stretch  = "Fill"   Stroke  = "Red"   StrokeThickness  = "5"   Canvas.Top  = "+"   = " />  

And the same kind of linegeometry,ellipsegeometry don't talk.

Graphics can be combined, of course, the path can also be combined GeometryGroup

OK, remember that the path is an object, and if the combined graph is 2 objects, 2 objects can have their own events. And path is itself, so the graph after the path combination of performance than the individual objects together good

<GeometryGroup> add a key as a resource, the data property of path only needs StaticResource to reference this resource.

Fill rule:

Combinedgeometry combined geometry, similar to the merging of drawing graphics, intersect, poor operation

Approximate structure as above, combined 2 graphs, how a combination method, have set

Transform

In addition to the 3 commonly used geometry, there are also custom graphics for comparing knowledge in graphics. So how do you write in a custom path? With PathGeometry

Path-> path.data->pathgeometry-> any number of pathfigure (including related attributes startpoint,isclosed,isfilled,segments) Subclasses of each pathsegment (for example, Linesegment,arcsegment,beziersegment,quadraticbeziersegment,polylinesegment, Polybeziersegment,polyquadraticbeziersegment)

The size of the arcsegment should be the long axis of the ellipse knowledge point and the short axis value (400,50) is the long axis of the ellipse equals 400, the total length is the total length of the 800,y axis is 100

There are 2 properties, islargearc whether large radians, or small radians, sweepdirection reversal? Default is counterclockwise

For Bézier Bezier curves, it is more complex and requires 3 points to create a line. The application is still very wide. Complex curves with visual tools to draw it, learned here just to make it easier to familiarize yourself with the code.

Micro-graphics language, such as data used when manually converting rectangle to paths in blend

 <  path  data  = "m2.5,2.5 l47.5,2.5 l47.5,97.5 l2.5,97.5 z"   Fill  = "Yellow"   Height  = "  Canvas.Left  = "94"   Stretch  = "Fill"   Stroke  = "Red"   StrokeThickness  = "5"   Canvas.Top  = "+"   = " />  

Here the data value, interpretation is meaningless, but there is a regular can see understand, here do not do too much to explain, will use tools to draw out.

Using this method to create the path, the steamgeometry is actually used, so the graphics cannot be modified in the code. If you want, you can

Simple use of paths, such as clipping paths

All elements are provided with the Clip property

Next, let's talk about the use of *geometry in geometrydrawing

The source used for image here uses the Drawingimage class, its drawing property, the subclass of the specified drawing, in addition to the GeometryDrawing class, and imagedrawing,vediodrawing, Glyphrundrawing, or use DrawingGroup to combine these drawing.

Drawing These classes cannot be placed on the interface and cannot be displayed. The image control's source, in addition to the use of drawingimage to fill images, such as the background color of the brush type, you can use the DrawingBrush fill, and then use geometry to draw the geometry. Drawvisual, about Drawvisual is inherited from visual, and the visual class is also the top of the element class, the basis of the comparison

Performance supplement, if you do not use path to draw, the equivalent of the practice, using canvas, and then put into many of the shapes inherited shape, such as line, circle, square, etc., then each element will have its own memory space and event handlers, the way to reduce the number of elements is better is the path element. Although path may also have limitations, it is certainly possible to reduce the element.

============= Chic Copyright line ==========www.ayjs.net===== Aaronyang ========= AY =========== Anhui six An Yangyang ========== without permission reprint =========

-------------------A small recommendation, the author's Affirmation, the reader's support. Pushing is not recommended is not important, it is important to hope that we can extend the WPF, do not let such a good technology disappear, please, let us make a contribution to WPF technology. -----------------

[Aaronyang] Write to own WPF4.5 note 18[geometry *geometry Illustrated]

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.