TextDecorations.Underline Property


Specifies an underline TextDecoration.

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

public static TextDecorationCollection Underline { get; }

Property Value

Type: System.Windows.TextDecorationCollection

A value that represents an underline TextDecoration.

The following example shows the location of an underline text decoration relative to the text.

Diagram of text decoration locations

Example of an underline text decoration

By default, Hyperlink uses a TextDecoration object to display an underline. For more information, see How to: Specify Whether a Hyperlink is Underlined.

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

Text decoration with linear gradient underline

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

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

// Use a linear gradient pen for the underline text decoration.
private void SetLinearGradientUnderline()
    // Create an underline text decoration. Default is underline.
    TextDecoration myUnderline = new TextDecoration();

    // Create a linear gradient pen for the text decoration.
    Pen myPen = 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.
    TextDecorationCollection myCollection = new TextDecorationCollection();
    TextBlock3.TextDecorations = myCollection;
<!-- 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
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top