GeometryDrawing.Pen Property
Gets or sets the Pen used to stroke this GeometryDrawing.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
<object> <object.Pen> <Pen .../> </object.Pen> </object>
Property Value
Type: System.Windows.Media.PenThe pen used to stroke this GeometryDrawing. The default value is Nothing.
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.
Imports System Imports System.Windows Imports System.Windows.Controls Imports System.Windows.Media Namespace SDKSample Partial Public Class PenExample Inherits Page Public Sub New() ' Create several geometries. Dim myRectangleGeometry As New RectangleGeometry() myRectangleGeometry.Rect = New Rect(0, 0, 50, 50) Dim myEllipseGeometry As New EllipseGeometry() myEllipseGeometry.Center = New Point(75, 75) myEllipseGeometry.RadiusX = 50 myEllipseGeometry.RadiusY = 50 Dim myLineGeometry As New LineGeometry() myLineGeometry.StartPoint = New Point(75, 75) myLineGeometry.EndPoint = New Point(75, 0) ' Create a GeometryGroup and add the geometries to it. Dim myGeometryGroup As New GeometryGroup() myGeometryGroup.Children.Add(myRectangleGeometry) myGeometryGroup.Children.Add(myEllipseGeometry) myGeometryGroup.Children.Add(myLineGeometry) ' Create a GeometryDrawing and use the GeometryGroup to specify ' its geometry. Dim myGeometryDrawing As New GeometryDrawing() myGeometryDrawing.Geometry = myGeometryGroup ' Add the GeometryDrawing to a DrawingGroup. Dim myDrawingGroup As New DrawingGroup() myDrawingGroup.Children.Add(myGeometryDrawing) ' Create a Pen to add to the GeometryDrawing created above. Dim myPen As 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. Dim firstStop As New GradientStop() firstStop.Offset = 0.0 Dim c1 As New Color() c1.A = 255 c1.R = 204 c1.G = 204 c1.B = 255 firstStop.Color = c1 Dim secondStop As New GradientStop() secondStop.Offset = 1.0 secondStop.Color = Colors.Purple Dim myLinearGradientBrush As New LinearGradientBrush() myLinearGradientBrush.GradientStops.Add(firstStop) myLinearGradientBrush.GradientStops.Add(secondStop) myPen.Brush = myLinearGradientBrush myGeometryDrawing.Pen = myPen ' Create an Image and set its DrawingImage to the Geometry created above. Dim myImage As New Image() myImage.Stretch = Stretch.None myImage.Margin = New Thickness(10) Dim myDrawingImage As New DrawingImage() myDrawingImage.Drawing = myDrawingGroup myImage.Source = myDrawingImage Me.Content = myImage End Sub End Class End Namespace
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="White"> <Image Stretch="None" Margin="20"> <Image.Source> <DrawingImage> <DrawingImage.Drawing> <DrawingGroup> <GeometryDrawing> <GeometryDrawing.Geometry> <GeometryGroup> <RectangleGeometry Rect="0,0,50,50" /> <EllipseGeometry Center="75,75" RadiusX="50" RadiusY="50" /> <LineGeometry StartPoint="75,75" EndPoint="75,0" /> </GeometryGroup> </GeometryDrawing.Geometry> <GeometryDrawing.Pen> <Pen Thickness="10" LineJoin="Round" EndLineCap="Triangle" StartLineCap="Round"> <Pen.Brush> <LinearGradientBrush> <GradientStop Offset="0.0" Color="#CCCCFF" /> <GradientStop Offset="1.0" Color="Purple" /> </LinearGradientBrush> </Pen.Brush> </Pen> </GeometryDrawing.Pen> </GeometryDrawing> </DrawingGroup> </DrawingImage.Drawing> </DrawingImage> </Image.Source> </Image> </Page>

More Code
| How to: Create a GeometryDrawing | This example shows how to create and display a GeometryDrawing. A GeometryDrawing enables you to create shape with a fill and an outline by associating a Pen and a Brush with a Geometry. The Geometry describes the shape's structure, the Brush describes the shape's fill, and the Pen describes the shape's outline. |
| How to: Paint an Area with a Drawing | This example shows how to paint an area with a drawing. To paint an area with a drawing, you use a DrawingBrush and one or more Drawing objects. The following example uses a DrawingBrush to paint an object with a drawing of two ellipses. |
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.