Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College

7. fejezet - Shapes (written by Csaba Biró)

7. fejezet - Shapes (written by Csaba Biró)

Built-in shapes

WPF also provides the familiar basic shapes are found in the System.Windows.Shapes class.

Built-in shapes are as follows:

  1. Line,

  2. Polyline ,

  3. Polygon,

  4. Rectangle,

  5. Ellipse,

  6. Path.


A Line draw a line between two points.

Key features

X1 Y1        initial coordinates,

X2 Y2        ending coordinates,

Stroke        line color,

StrokeThickness        stroke thickness,

StrokeStartLineCap        line endings,

StrokeEndLineCap        line endings,

StrokeDashCap        line endings,

StrokeDashArray        sections and length of gaps.

Example VII.1 Line

VII.1. Line

<Line X1="20" Y1="10" X2="480" Y2="10"



       StrokeDashArray="1 1">


<Line X1="20" Y1="40" X2="480" Y2="40"



       StrokeDashArray="1 0.5">


<Line X1="20" Y1="70" X2="480" Y2="70"



       StrokeDashArray="1 1.5"





<Line X1="10" Y1="100" X2="490" Y2="100"



       StrokeDashArray="1 2 0.4 0.3 0.2 0.1">  


<Line X1="10" Y1="130" X2="490" Y2="130" Stroke="Black"


       StrokeDashArray="0 1"




Polyline is suited to draw lines consist of several sections. Most features of line shapes are already known.

Key features:

Points        X and Y coordinates,

StrokeLineJoin        rounding of the peaks,

StrokeMiterLimit        thinning of the peaks.

Example VII.2 PolyLine

VII.2. PolyLine


      Points="10 10 10 100 60 40 100 70 140 40 190 100 190 10 10 10"



      StrokeDashArray="1 1"




Polygon is for drawing polygons. It has a new feature (Fill) has been described in previous figures.

Example VII.3 Polygon

VII.3. Polygon

<Polygon Points="10 10 100 70 10 130"





               <GradientStop Color="Yellow" Offset="0.1"/>

               <GradientStop Color="Red" Offset="0.3"/>

               <GradientStop Color="Yellow" Offset="0.5"/>

               <GradientStop Color="Red" Offset="0.7"/>

               <GradientStop Color="Yellow" Offset="0.9"/>




<Polygon Points="200 100 200 200 300 200 300 10"

         Stroke="Blue" StrokeThickness="10"




<Polygon Points="400 10 380 60 340 75 380 100 400 140 420 100 460 75 420 60 ">


          <ImageBrush ImageSource="/Pictures/Nap.gif"/>



Ellipse és Rectangle

They have a drawing ability (rectangle and ellipse) completed with Width and Height features.

Example VII.4 Ellipse and Rectangle

VII.4. Ellipse and Rectangle


        <Ellipse Width="100" Height="100" StrokeThickness="10">



                    <GradientStop Offset="0.3" Color="Yellow"/>

                    <GradientStop Offset="0.6" Color="Red"/>





                        <GradientStop Offset="0" Color="Violet"/>

                        <GradientStop Offset="0.7" Color="Lavender"/>




            <Rectangle Width="300" Height="200"



                <DrawingBrush Viewport="1,1,0.25,0.25" TileMode="Tile">



                            <GeometryDrawing Brush="White">


                            <GeometryDrawing Brush="Green">



                                   <EllipseGeometry RadiusX="10" RadiusY="10"/>

                                   <EllipseGeometry RadiusX="100" RadiusY="1"/>