Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
TextDecoration Constructor (TextDecorationLocation, Pen, Double, TextDecorationUnit, TextDecorationUnit)

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


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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft