Polygon Object

Draws a polygon, which is a connected series of lines that form a closed shape.

XAML
<Polygon .../>
Scripting
To create an object using scripting, see CreateFromXAML.

Properties

Canvas.Left, Canvas.Top, Canvas.ZIndex, Clip, Cursor, Fill, FillRule, Height, Name, Opacity, OpacityMask, Points, RenderTransform, RenderTransformOrigin, Resources, Stretch, Stroke, StrokeDashArray, StrokeDashCap, StrokeDashOffset, StrokeEndLineCap, StrokeLineJoin, StrokeMiterLimit, StrokeStartLineCap, StrokeThickness, Tag, Triggers, Width

Methods

AddEventListener, CaptureMouse, Equals, FindName, GetHost, GetParent, GetValue, ReleaseMouseCapture, RemoveEventListener, SetValue

Events

Loaded, MouseEnter, MouseLeave, MouseLeftButtonDown, MouseLeftButtonUp, MouseMove

Remarks

The simplest true polygon is a triangle, in which case the Points property will have three entries. A Polygon with two points in Points will still render so long as it has a nonzero StrokeThickness value and a nonnull Stroke value, but that same result could be accomplished with Line. A Polygon with only one point will not render.

Examples

The following example shows how to use a Polygon to create a triangle.

XAML
<Canvas
  xmlns="https://schemas.microsoft.com/client/2007" 
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">
  <!-- This polygon shape uses pre-defined color values for its Stroke and
       Fill properties.
       The SolidColorBrush's Opacity property affects the fill color in
       this case by making it slightly transparent (opacity of 0.4) so
       that it blends with any underlying color. -->
  <Polygon
    Points="300,200 400,125 400,275 300,200"
    Stroke="Purple"
    StrokeThickness="2">
    <Polygon.Fill>
       <SolidColorBrush Color="Blue" Opacity="0.4"/>
    </Polygon.Fill>
  </Polygon> 
 
</Canvas>

The following illustration shows the rendered shape.

Polygon illustration

Polygon illustration

See Also

Shapes Overview
Shape