This documentation is archived and is not being maintained.

Pen.ThicknessProperty Field

Identifies the Thickness dependency property.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

public static readonly DependencyProperty ThicknessProperty

Field Value

Type: System.Windows.DependencyProperty
The identifier for the Thickness dependency property.

This example shows how use a Pen to outline a shape. To create a simple Pen, you need only specify its Thickness and Brush. You can create more complex pen's by specifying a DashStyle, DashCap, LineJoin, StartLineCap, and EndLineCap.

The following example uses a Pen to outline a shape defined by a GeometryDrawing.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace SDKSample
    public partial class PenExample : Page
        public PenExample()
            // Create several geometries.
            RectangleGeometry myRectangleGeometry = new RectangleGeometry();
            myRectangleGeometry.Rect = new Rect(0, 0, 50, 50);
            EllipseGeometry myEllipseGeometry = new EllipseGeometry();
            myEllipseGeometry.Center = new Point(75, 75);
            myEllipseGeometry.RadiusX = 50;
            myEllipseGeometry.RadiusY = 50;
            LineGeometry myLineGeometry = new LineGeometry();
            myLineGeometry.StartPoint = new Point(75, 75);
            myLineGeometry.EndPoint = new Point(75, 0);

            // Create a GeometryGroup and add the geometries to it.
            GeometryGroup myGeometryGroup = new GeometryGroup();

            // Create a GeometryDrawing and use the GeometryGroup to specify
            // its geometry.
            GeometryDrawing myGeometryDrawing = new GeometryDrawing();
            myGeometryDrawing.Geometry = myGeometryGroup;

            // Add the GeometryDrawing to a DrawingGroup.
            DrawingGroup myDrawingGroup = new DrawingGroup();

            // Create a Pen to add to the GeometryDrawing created above.
            Pen myPen = new Pen();
            myPen.Thickness = 10;
            myPen.LineJoin = PenLineJoin.Round;
            myPen.EndLineCap = PenLineCap.Round;

            // Create a gradient to use as a value for the Pen's Brush property.
            GradientStop firstStop = new GradientStop();
            firstStop.Offset = 0.0;
            Color c1 = new Color();
            c1.A = 255;
            c1.R = 204;
            c1.G = 204;
            c1.B = 255;
            firstStop.Color = c1;
            GradientStop secondStop = new GradientStop();
            secondStop.Offset = 1.0;
            secondStop.Color = Colors.Purple;

            LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();

            myPen.Brush = myLinearGradientBrush;
            myGeometryDrawing.Pen = myPen;

            // Create an Image and set its DrawingImage to the Geometry created above.
            Image myImage = new Image();
            myImage.Stretch = Stretch.None;
            myImage.Margin = new Thickness(10);

            DrawingImage myDrawingImage = new DrawingImage();
            myDrawingImage.Drawing = myDrawingGroup;
            myImage.Source = myDrawingImage;

            this.Content = myImage;



  <Image Stretch="None" Margin="20">
                  <RectangleGeometry Rect="0,0,50,50" />
                  <EllipseGeometry Center="75,75" RadiusX="50" RadiusY="50" />
                  <LineGeometry StartPoint="75,75" EndPoint="75,0" />
                      <GradientStop Offset="0.0" Color="#CCCCFF" />
                      <GradientStop Offset="1.0" Color="Purple" />


A GeometryDrawing

Outlines produces by a Pen

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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