WPF 10 day Nineth Day of cultivation-geometry

Source: Internet
Author: User

Geometry

Draws lines, rectangles, and ellipses, respectively, using LineGeometry, RectangleGeometry, and EllipseGeometry objects.

Use GeometryGroup to draw combined graphics.

<window x:class= "Wpfdemo.geometrydemo" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d= "http://schemas.microsoft.com/expression/blend/ "Xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 "xmlns:local=" CLR-NAMESPACE:WPFD Emo "mc:ignorable=" D "windowstartuplocation=" Centerscreen "title=" Geometrydemo "height=" "width=" 80 0 "> <Canvas> <stackpanel canvas.top=" > <textblock text= "Draw non-intersecting combined graphics" &GT;&LT;/TEXTB Lock> <path strokethickness= "1" fill= "Yellow" stroke= "Black" margin= "5" > <path.dat                        A > <!--use GeometryGroup to assemble graphics--<geometrygroup >                        <!--draw Lines--<linegeometry startpoint= "10,20" endpoint= "100,20"/>     <!--draw a rectangle--                   <rectanglegeometry rect= "10,50,100,50"/> <!--drawing Ellipse--                <ellipsegeometry radiusx= "radiusy=" center= "60,160"/> </GeometryGroup> </Path.Data> </Path> </StackPanel> <stackpanel canvas.top= "Ten" Ca Nvas.  left= > <textblock text= "nonzero mode fill graphics" ></TextBlock> <path strokethickness= "1" Fill= "Yellow" stroke= "Black" margin= "5" > <path.data > <!--using GeometryGroup                        Combine collection graphics--<geometrygroup fillrule= "Nonzero" > <!--drawing Lines--                        <linegeometry startpoint= "10,20" endpoint= "100,20"/> <!--draw a rectangle--                        <rectanglegeometry rect= "10,50,100,50"/> <!--drawing Ellipse-- <ellipsegEometry radiusx= "radiusy=" center= "60,50"/> </GeometryGroup> </path.d            ata> </Path> </StackPanel> <stackpanel canvas.top= "canvas.left=" > <textblock text= "evenodd mode fill Graphics" ></TextBlock> <path strokethickness= "1" fill= "Yellow" S                    Troke= "Black" margin= "5" > <path.data > <!--use the GeometryGroup group to assemble graphics-- <geometrygroup fillrule= "EvenOdd" > <!--draw a line---& Lt LineGeometry startpoint= "10,20" endpoint= "100,20"/> <!--draw rectangles--&L T RectangleGeometry rect= "10,50,100,50"/> <!--draw Ellipse--<ellipsegeo Metry radiusx= "radiusy=" center= "60,50"/> </GeometryGroup> </path.dat A> &LT;/path> </StackPanel> </Canvas></Window> 

using Combinedgeometry Combine Shapes

Use the enumeration property of GeometryCombineMode to apply some Boolean operations to the composite graphic.

Union: Two regions are combined by merging two regions. The new graphic is two graphics.

Inntersect: Merges two regions by using the intersection of two regions. The new graphic intersects the two graphs.

Xor: Merges in the first drawing but not in the area in the second drawing, and in the area of the second shape but not in the first shape. The new area consists of (A-B) + (B-A).

Exclude: The second shape is always removed from the first drawing.

<window x:class= "Wpfdemo.combinedgeometrydemo" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/ Presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:d=" http://schemas.microsoft.com/e xpression/blend/2008 "xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 "xmlns:local=" cl R-namespace:wpfdemo "mc:ignorable=" D "windowstartuplocation=" Centerscreen "title=" Combinedgeometrydem O "height=" 530 "width=" > <Canvas> <stackpanel canvas.left= "Ten" canvas.top= "ten" > &L T                TextBlock text= "Union calculation combination Graph"/> <path stroke= "Black" strokethickness= "1" fill= "Yellow" > <Path.Data> <!---Use Union to combine multiple shapes--<combinedgeometry Geometrycombine  Mode= "Union" > <CombinedGeometry.Geometry1> <ellipsegeometry radiusx= "radiusy=" "center="75,75 "/> </CombinedGeometry.Geometry1> <combinedgeometry.geometr                        y2> <ellipsegeometry radiusx= "radiusy=" center= "125,75"/>            </CombinedGeometry.Geometry2> </CombinedGeometry> </Path.Data> </Path> </StackPanel> <stackpanel canvas.left= "Up" canvas.top= "ten" > &lt ;                TextBlock text= "Exclude compute Combo Graph"/> <path stroke= "Black" strokethickness= "1" fill= "Yellow" > <Path.Data> <!---use exclude to combine multiple graphs--<combinedgeometry geometrycom Binemode= "Exclude" > <CombinedGeometry.Geometry1> <ellipsegeo                        Metry radiusx= "radiusy=" center= "75,75"/> </CombinedGeometry.Geometry1> <combinedgeometry.geometry2> <ellipsegeometry radiusx= "radiusy=" center= "125,75"/> </CombinedGeometry.Geometry2> </CombinedGeometry> </ path.data> </Path> </StackPanel> <stackpanel canvas.left= "ten" canvas.top= "250" &            Gt                <textblock text= "intersect compute Combo graph"/> <path stroke= "Black" strokethickness= "1" fill= "Yellow" > <Path.Data> <!---use intersect to combine multiple graphs--<combinedgeometry Geo Metrycombinemode= "Intersect" > <CombinedGeometry.Geometry1> <                        EllipseGeometry radiusx= "radiusy=" center= "75,75"/> </CombinedGeometry.Geometry1> <CombinedGeometry.Geometry2> <ellipsegeometry radiusx= "Rad" Iusy= "50" center= "125,75"/> </CombinedGeometry.Geometry2> </combinedgeometry&                Gt </Path.Data> </Path> </StackPanel> <stackpanel canvas.left= "2" canvas.top= " "> <textblock text=" xor compute Combo Graphic "/> <path stroke=" Black "strokethickness=" 1 "fill=" Yello W "> <Path.Data> <!---combine multiple graphs with XOR--<combinedgeome Try geometrycombinemode= "Xor" > <CombinedGeometry.Geometry1> &lt ;                        EllipseGeometry radiusx= "radiusy=" center= "75,75"/> </CombinedGeometry.Geometry1> <CombinedGeometry.Geometry2> <ellipsegeometry radiusx= "Rad" Iusy= "center=" 125,75 "/> </CombinedGeometry.Geometry2> </combined Geometry> </Path.Data> </Path> </StackPanel> </canvas></wind Ow>

PathGeometry Object

The PathGeometry object is the most powerful element in a collection drawing, using which you can draw complex shapes, such as arcs, curves, ellipses, lines, and rectangles. Each Pathgeomery object uses one and more PathFigure objects, which are stored in the PathGeometry.Figures collection. Each PathFigure object can consist of one or more PathSegment objects. Each Pathgeomery object uses one and more PathFigure objects that exist in the Paathgeometryfigures collection. Each PathFigure object has one or more PathSegment objects.

Important attributes of PathFigure:

StartPoint: Specify the starting point of the segment

Segments: A collection of PathSegment objects that are used to draw graphics.

IsClosed: If set to true, a straight line connection start and end point is added.

Isfilled: If set to true, the inner area of the graphic is populated with a path.fill brush.

PathSegment Derived classes:

LineSegment: Creates a line between two points.

ArcSegment: Creates an arc between two points.

BezierSegment: Creates a Bezier curve between two points.

QuadraticBezierSegment: Create a two-time bell curve between two points in PathFigure.

PolyLineSegment: Creates a series of straight lines that you can use to achieve the same effect using multiple LineSegment objects, but using polylinesegment is easier.

Polybeeiersegment: Creates one or more three-time Bezier curves.

PolyQuadraticBezierSegment: Creates a series of two-time Bezier segments.

Drawing a drawing using pathgeeometry

<window x:class= "Wpfdemo.pathgeometrydemo" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d= "HTTP://SCHEMAS.MICROSOFT.COM/EXPRESSION/BLEND/2 008 "xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 "xmlns:local=" clr-namespace:wpfde Mo "mc:ignorable=" D "title=" Pathgeometrydemo "height=" "width=" > <Canvas> <!--Paint Line-to-<stackpanel canvas.top= "canvas.left=" > <textblock text= "draw line Isclose set to False"/&            Gt                        <path stroke= "Blue" > <Path.Data> <PathGeometry>                            <pathfigure isclosed= "True" startpoint= "10,10" > <!--using linesegment to draw a line--            <linesegment point= "10,100"/> <linesegment point= "100,50"/>            </PathFigure> </PathGeometry> </Path.Data> < /path> </StackPanel> <stackpanel canvas.top= "ten" canvas.left= "> <textblock"                    text= "Draw line Isclose set to False"/> <path stroke= "Blue" > <Path.Data>                            <PathGeometry> <pathfigure isclosed= "False" startpoint= "10,10" >                            <!--draw lines with linesegment--<linesegment point= "10,100"/> <linesegment point= "100,50"/> </PathFigure> </pathgeometry&                Gt </Path.Data> </Path> </StackPanel> <!--drawing arcs--<stackpanel Can Vas.   left= "canvas.top=" > <path stroke= "Black" strokethickness= "1" > <Path.Data>                 <PathGeometry> <PathGeometry.Figures> <p                                    athfigurecollection> <pathfigure startpoint= "10,10" >                                            <PathFigure.Segments> <PathSegmentCollection> <!--drawing ARCS--<arcsegment size= "100,50" Rotation                                        Angle= "islargearc=" True "sweepdirection=" counterclockwise "point=" 200,100 "></ArcSegment>                                </PathSegmentCollection> </PathFigure.Segments>                        </PathFigure> </PathFigureCollection> </PathGeometry.Figures> </PathGeometry> </Path.Data> </ Path> </staCkpanel> <!--draw Bézier curves--<stackpanel canvas.top= "canvas.left=" > <path Str                        Oke= "Black" strokethickness= "5" > <Path.Data> <PathGeometry>                            <pathfigure startpoint= "10,10" > <!--drawing Bézier curves--                    <beziersegment point1= "130,30" point2= "40,140" point3= "150,150"/> </PathFigure>     </PathGeometry> </Path.Data> </Path> </StackPanel> </Canvas></Window>

WPF 10 day Nineth Day of cultivation-geometry

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.