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
)

Parameters

location
Type: System.Windows.TextDecorationLocation

The location of the text decoration.

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

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

penOffsetUnit
Type: System.Windows.TextDecorationUnit

The units used to interpret the value of penOffset.

penThicknessUnit
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(
            TextDecorationLocation.Baseline,
            new Pen(Brushes.Maroon, 1),
            2.0,
            TextDecorationUnit.Pixel,
            TextDecorationUnit.Pixel);

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

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft