Pročitaj na engleskom Uredi

Dijelite putem


TextDecorations Class

Definition

Provides a set of static predefined text decorations.

C#
public static class TextDecorations
Inheritance
TextDecorations

Examples

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

C#
// 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;
}
XAML
<!-- Use the default font values for the strikethrough text decoration. -->
<TextBlock
  TextDecorations="Strikethrough"
  FontSize="36" >
  The quick red fox
</TextBlock>

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.

XAML
<!-- 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".

XAML
<!-- 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.

C#
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:

XAML
<!-- 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: Specify Whether a Hyperlink is Underlined.

Remarks

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.

Diagram of text decoration locations
Example of text decoration types

XAML Attribute Usage

<object textDecorationsProperty="textDecorationType[,textDecorationType]"/>  

XAML Values

textDecorationType
The type of text decoration: Baseline, OverLine, Strikethrough, or Underline. More than one decoration is permitted, with values separated by commas. You can also specify "None" to indicate no type of text decoration.

Properties

Baseline

Specifies a baseline TextDecoration.

OverLine

Specifies an overline TextDecoration.

Strikethrough

Specifies a strikethrough TextDecoration.

Underline

Specifies an underline TextDecoration.

Applies to

Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10