This documentation is archived and is not being maintained.

TextDecoration Constructor (TextDecorationLocation, Pen, Double, TextDecorationUnit, TextDecorationUnit)

Initializes a new instance of the TextDecoration class with the specified Location, Pen, PenOffset, PenOffsetUnit, and PenThicknessUnit values.

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

public TextDecoration(
	TextDecorationLocation location,
	Pen pen,
	double penOffset,
	TextDecorationUnit penOffsetUnit,
	TextDecorationUnit penThicknessUnit
You cannot use constructors in XAML.


Type: System.Windows.TextDecorationLocation

The location of the text decoration.

Type: System.Windows.Media.Pen

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

Type: System.Double

The vertical displacement from the text decoration's location. A negative value moves the decoration lower, while a positive value moves the decoration higher.

Type: System.Windows.TextDecorationUnit

The units used to interpret the value of penOffset.

Type: System.Windows.TextDecorationUnit

The units used to interpret the value of the Thickness for the pen.

The following code example shows how to create a TextDecoration by using the location, pen, penOffset, penOffsetUnit, and penThicknessUnit parameters.

// Use a Maroon pen for the baseline text decoration. 
private void SetMaroonBaseline()
    // Create an baseline text decoration 2 units lower than the default.
    TextDecoration myBaseline = new TextDecoration(
            new Pen(Brushes.Maroon, 1),

    // Set the baseline decoration to a TextDecorationCollection and add it to the text block.
    TextDecorationCollection myCollection = new TextDecorationCollection();
    TextBlock2.TextDecorations = myCollection;
    <TextDecoration Location="Baseline" PenOffset="2" PenOffsetUnit="Pixel" PenThicknessUnit="Pixel" >
        <Pen Brush="Maroon" Thickness="1" />
  The quick red fox

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