This article continues from Graphics in Silverlight 5: Part I and Graphics in
Silverlight 5: Part II.
In the third part of this series, we shall continue exploring other Shape
elements. We begin with the Polygon.
Polygon
Using this element, you can draw polygonal shapes. A polygonal shape is a
connected set of lines forming a closed shape.
Let us see how to use this element in Silverlight. Create a Silverlight
application named PolygonDemo.
Add the following markup:
<Polygon Points="75,100
75,50 150,10 225,50 225,100 150,140 75,100"
Fill="Navy" Stroke="Red" StrokeThickness="4">
</Polygon>
This markup draws a series of line, first from 75,100 to 75, 50 then from 75,50
to 150,10, then from 150, 10 to 225, 50. Then from 225, 50 to 225, 100 and from
225, 100 to 150, 150 and finally from 150, 150 back to the beginning 75,100.
The outcome of this markup is shown in Figure 1.

Figure 1
But the Polygon element is not just useful to draw polygons but can be
manipulated to draw triangles, parallelograms, and such shapes.
For instance, to draw a parallelograms, you can use the following markup:
<Polygon Points="75,100
100,50 200,50 175,100 75,100"
Fill="RoyalBlue" Stroke="Black" StrokeThickness="2">
</Polygon>
The outcome of this markup is shown in Figure 2.

Figure 2
You can even draw random shapes such as the one shown in Figure 3 using the
Polygon element.

Figure 3
To generate such a shape, you would need to write the following markup:
<Polygon Points="75,100
100,125 200,125 225,50 225,100 150,140 75,100"
Fill="Red" Stroke="Black" StrokeThickness="2">
</Polygon>
Polyline
This element is similar to the Polygon element, except that the last points need
not connect back to the first.
The following XAML markup shows how to create a polyline.
<Polyline
Points="75,100 100,50 200,50 50,75 120,80"
Fill="RoyalBlue" StrokeThickness="2">
</Polyline>
The outcome of this markup is shown in Figure 4.


Gowtham RajamanickamPosted May 20, 2015, 1:01 AM
good