Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Shape Class

Provides a base class for shape elements, such as Ellipse, Polygon, and Rectangle.

Namespace:  System.Windows.Shapes
Assembly:  PresentationFramework (in PresentationFramework.dll)

[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
public abstract class Shape : FrameworkElement
This class is abstract; see Inheritance Hierarchy for derived non-abstract classes usable in XAML.

This example shows you how to draw lines by using the Line element.

To draw a line, create a Line element. Use its X1 and Y1 properties to set its start point; and use its X2 and Y2 properties to set its end point. Finally, set its Stroke and StrokeThickness because a line without a stroke is invisible.

Setting the Fill element for a line has no effect, because a line has no interior.

The following example draws three lines inside a Canvas element.

<Canvas Height="300" Width="300">

  <!-- Draws a diagonal line from (10,10) to (50,50). -->
    X1="10" Y1="10"
    X2="50" Y2="50"
    StrokeThickness="4" />

  <!-- Draws a diagonal line from (10,10) to (50,50)
       and moves it 100 pixels to the right. -->
    X1="10" Y1="10"
    X2="50" Y2="50"
      <RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5" RadiusX="0.5" RadiusY="0.5">
          <GradientStop Color="Red" Offset="0" />
          <GradientStop Color="Blue" Offset="0.25" />

  <!-- Draws a horizontal line from (10,60) to (150,60). -->
     X1="10" Y1="60"
     X2="150" Y2="60"


This example is part of a larger sample; for the complete sample, see Shape Elements Sample.

More Code

How to: Draw an Ellipse or a Circle This example shows how to draw ellipses and circles by using the Ellipse element. To draw an ellipse, create an Ellipse element and specify its Width and Height. Use its Fill property to specify the Brush that is used to paint the interior of the ellipse. Use its Stroke property to specify the Brush that is used to paint the outline of the ellipse. The StrokeThickness property specifies the thickness of the ellipse outline.
How to: Draw a Closed Shape by Using the Polygon Element This example shows how to draw a closed shape by using the Polygon element. To draw a closed shape, create a Polygon element and use its Points property to specify the vertices of a shape. A line is automatically drawn that connects the first and last points. Finally, specify a Fill, a Stroke, or both.
How to: Draw a Polyline by Using the Polyline Element This example shows how to draw a polyline, which is a series of connected lines, by using the Polyline element.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

© 2017 Microsoft