Pen Class
Describes how a shape is outlined.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
The Pen type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Pen() | Initializes a new instance of the Pen class. |
![]() | Pen(Brush, Double) | Initializes a new instance of the Pen class with the specified Brush and thickness. |
| Name | Description | |
|---|---|---|
![]() | Brush | Gets or sets the fill the outline produced by this Pen. |
![]() | CanFreeze | Gets a value that indicates whether the object can be made unmodifiable. (Inherited from Freezable.) |
![]() | DashCap | Gets or sets a value that specifies how the ends of each dash are drawn. |
![]() | DashStyle | Gets or sets a value that describes the pattern of dashes generated by this Pen. |
![]() | DependencyObjectType | Gets the DependencyObjectType that wraps the CLR type of this instance. (Inherited from DependencyObject.) |
![]() | Dispatcher | Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.) |
![]() | EndLineCap | Gets or sets the type of shape to use at the end of a stroke. |
![]() | HasAnimatedProperties | Gets a value that indicates whether one or more AnimationClock objects is associated with any of this object's dependency properties. (Inherited from Animatable.) |
![]() | IsFrozen | Gets a value that indicates whether the object is currently modifiable. (Inherited from Freezable.) |
![]() | IsSealed | Gets a value that indicates whether this instance is currently sealed (read-only). (Inherited from DependencyObject.) |
![]() | LineJoin | Gets or sets the type of joint used at the vertices of a shape's outline. |
![]() | MiterLimit | Gets or sets the limit on the ratio of the miter length to half this pen's Thickness. |
![]() | StartLineCap | Gets or sets the type of shape to use at the beginning of a stroke. |
![]() | Thickness | Gets or sets the thickness of the stroke produced by this Pen. |
| Name | Description | |
|---|---|---|
![]() | ApplyAnimationClock(DependencyProperty, AnimationClock) | Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the SnapshotAndReplace handoff behavior is used. (Inherited from Animatable.) |
![]() | ApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior) | Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the specified HandoffBehavior is used. (Inherited from Animatable.) |
![]() | BeginAnimation(DependencyProperty, AnimationTimeline) | Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the SnapshotAndReplace handoff behavior is used. (Inherited from Animatable.) |
![]() | BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior) | Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the specified HandoffBehavior is used. (Inherited from Animatable.) |
![]() | CheckAccess | Determines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.) |
![]() | ClearValue(DependencyProperty) | Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject.) |
![]() | ClearValue(DependencyPropertyKey) | Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject.) |
![]() | Clone | Creates a modifiable clone of this Pen, making deep copies of this object's values. When copying dependency properties, this method copies resource references and data bindings (but they might no longer resolve) but not animations or their current values. |
![]() | CloneCurrentValue | Creates a modifiable clone of this Pen object, making deep copies of this object's current values. Resource references, data bindings, and animations are not copied, but their current values are. |
![]() | CoerceValue | Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject. (Inherited from DependencyObject.) |
![]() | Equals | Determines whether a provided DependencyObject is equivalent to the current DependencyObject. (Inherited from DependencyObject.) |
![]() | Freeze() | Makes the current object unmodifiable and sets its IsFrozen property to true. (Inherited from Freezable.) |
![]() | GetAnimationBaseValue | Returns the non-animated value of the specified DependencyProperty. (Inherited from Animatable.) |
![]() | GetAsFrozen | Creates a frozen copy of the Freezable, using base (non-animated) property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.) |
![]() | GetCurrentValueAsFrozen | Creates a frozen copy of the Freezable using current property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.) |
![]() | GetHashCode | Gets a hash code for this DependencyObject. (Inherited from DependencyObject.) |
![]() | GetLocalValueEnumerator | Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetValue | Returns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject.) |
![]() | InvalidateProperty | Re-evaluates the effective value for the specified dependency property (Inherited from DependencyObject.) |
![]() | ReadLocalValue | Returns the local value of a dependency property, if it exists. (Inherited from DependencyObject.) |
![]() | SetCurrentValue | Sets the value of a dependency property without changing its value source. (Inherited from DependencyObject.) |
![]() | SetValue(DependencyProperty, Object) | Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject.) |
![]() | SetValue(DependencyPropertyKey, Object) | Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject.) |
![]() | ShouldSerializeProperty | Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property. (Inherited from DependencyObject.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | VerifyAccess | Enforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.) |
| Name | Description | |
|---|---|---|
![]() ![]() | BrushProperty | Identifies the Brush dependency property. |
![]() ![]() | DashCapProperty | Identifies the DashCap dependency property. |
![]() ![]() | DashStyleProperty | Identifies the DashStyle dependency property. |
![]() ![]() | EndLineCapProperty | Identifies the EndLineCap dependency property. |
![]() ![]() | LineJoinProperty | Identifies the LineJoin dependency property. |
![]() ![]() | MiterLimitProperty | Identifies the MiterLimit dependency property. |
![]() ![]() | StartLineCapProperty | Identifies the StartLineCap dependency property. |
![]() ![]() | ThicknessProperty | Identifies 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(); myGeometryGroup.Children.Add(myRectangleGeometry); myGeometryGroup.Children.Add(myEllipseGeometry); myGeometryGroup.Children.Add(myLineGeometry); // 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(); myDrawingGroup.Children.Add(myGeometryDrawing); // 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(); 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. 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; } } }
<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>

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.





