This documentation is archived and is not being maintained.

TextDecoration.Pen Property

Gets or sets the Pen used to draw the text decoration.

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

Public Property Pen As Pen
    <Pen .../>

Property Value

Type: System.Windows.Media.Pen
The Pen used to draw the text decoration. If this value is null, the decoration color matches the text to which it is applied and the decoration's thickness is set to the font's recommended thickness.

Identifier field


Metadata properties set to true


The following example shows a text decoration that has been styled with a linear gradient brush and a dashed pen.

Example of an underline styled with a linear gradient brush and dashed pen

Text decoration with linear gradient underline

In the following code example, an underline text decoration is created with a linear gradient brush for the dashed pen.

		' Use a linear gradient pen for the underline text decoration.
		Private Sub SetLinearGradientUnderline()
			' Create an underline text decoration. Default is underline.
			Dim myUnderline As New TextDecoration()

			' Create a linear gradient pen for the text decoration.
			Dim myPen As New Pen()
			myPen.Brush = New LinearGradientBrush(Colors.Yellow, Colors.Red, New Point(0, 0.5), New Point(1, 0.5))
			myPen.Brush.Opacity = 0.5
			myPen.Thickness = 1.5
			myPen.DashStyle = DashStyles.Dash
			myUnderline.Pen = myPen
			myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended

			' Set the underline decoration to a TextDecorationCollection and add it to the text block.
			Dim myCollection As New TextDecorationCollection()
			TextBlock3.TextDecorations = myCollection
		End Sub

<!-- Use a linear gradient pen for the underline text decoration. -->
<TextBlock FontSize="36">the lazy brown dog.
          <Pen Thickness="1.5">
              <LinearGradientBrush Opacity="0.5"
                StartPoint="0,0.5"  EndPoint="1,0.5">
                  <GradientStop Color="Yellow" Offset="0" />
                  <GradientStop Color="Red" Offset="1" />
              <DashStyle Dashes="2"/>

.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.