Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TextDecorations Class

Provides a set of static predefined text decorations.

Namespace: System.Windows
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public static class TextDecorations
public final class TextDecorations
public final class TextDecorations
<object textDecorationsProperty="textDecorationType[,textDecorationType]"/>

 textDecorationType  The type of text decoration: Baseline, OverLine, Strikethrough, or Underline. You can also specify "None" to indicate no type of text decoration. 

There are four types of text decorations: baseline, overline, strikethrough, and underline. The following example shows the locations of the text decorations relative to the text.

Example of text decoration types


Diagram of text decoration locations

In the following example, a strikethrough text decoration uses the default font value.

<!-- Use the default font values for the strikethrough text decoration. -->
<TextBlock
  TextDecorations="Strikethrough"
  FontSize="36" >
  The quick red fox
</TextBlock>

// Use the default font values for the strikethrough text decoration.
private void SetDefaultStrikethrough()
{
    // Set the underline decoration directly to the text block.
    TextBlock1.TextDecorations = TextDecorations.Strikethrough;
}

You can also specify multiple text decorations for the same text. In the following example, an underline and overline text decoration are used for the same text.

<!-- Use both an underline and overline text decoration for the same text. -->
<TextBlock TextDecorations="Underline, Overline">
  The quick red fox
</TextBlock>

You can use the string value "None" to indicate that there are no text decorations in the TextDecorations collection. In the following example, the TextDecorations collection is set to "None".

<!-- Set the text decoration collection to None to indicate no decorations. -->
<TextBlock TextDecorations="None">
  The quick red fox
</TextBlock>

You can remove all text decorations from text by using the Clear method. In the following example, the TextDecorations collection is cleared.

TextBlock2.TextDecorations.Clear();

By default, Hyperlink uses a TextDecoration object to display an underline. The following markup sample shows a Hyperlink defined with and without an underline:

<!-- Hyperlink with default underline. -->
<Hyperlink NavigateUri="http://www.msn.com">
  MSN Home
</Hyperlink>

<Run Text=" | " />

<!-- Hyperlink with no underline. -->
<Hyperlink Name="myHyperlink" TextDecorations="None"
           MouseEnter="OnMouseEnter"
           MouseLeave="OnMouseLeave"
           NavigateUri="http://www.msn.com">
  My MSN
</Hyperlink>

TextDecoration objects can be performance intensive to instantiate, particularly if you have many Hyperlink objects. For more information, see How to: Use a Text Decoration with a Hyperlink.

System.Object
  System.Windows.TextDecorations
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.