TextDecorations 类

定义

提供一组静态预定义文本修饰。

public ref class TextDecorations abstract sealed
public static class TextDecorations
type TextDecorations = class
Public Class TextDecorations
继承
TextDecorations

示例

在以下示例中,删除线文本修饰使用默认字体值。

// 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;
}
' Use the default font values for the strikethrough text decoration.
Private Sub SetDefaultStrikethrough()
    ' Set the underline decoration directly to the text block.
    TextBlock1.TextDecorations = TextDecorations.Strikethrough
End Sub
<!-- Use the default font values for the strikethrough text decoration. -->
<TextBlock
  TextDecorations="Strikethrough"
  FontSize="36" >
  The quick red fox
</TextBlock>

还可以为同一文本指定多个文本修饰。 在以下示例中,对同一文本使用下划线和超行文本修饰。

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

可以使用字符串值“None”来指示集合中 TextDecorations 没有文本修饰。 在以下示例中,集合 TextDecorations 设置为“None”。

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

可以使用该方法从文本 Clear 中删除所有文本修饰。 在以下示例中,清除 TextDecorations 集合。

TextBlock2.TextDecorations.Clear();
TextBlock2.TextDecorations.Clear()

默认情况下, Hyperlink 使用对象 TextDecoration 来显示下划线。 以下标记示例演示使用和不使用下划线定义的 Hyperlink

<!-- 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 对象可能会消耗大量性能来实例化,尤其是如果你有许多 Hyperlink 对象时。 有关详细信息,请参阅 “如何:指定超链接是否带下划线”。

注解

有四种类型的文本修饰:基线、超行、删除线和下划线。 以下示例显示相对于文本的文本修饰的位置。

文本修饰位置关系图 文本修饰类型示例

XAML 属性用法

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

XAML 值

textDecorationType 文本修饰的类型: BaselineOverLineStrikethroughUnderline。 允许使用多个修饰,值用逗号分隔。 还可以指定“None”来指示没有类型的文本修饰。

属性

名称 说明
Baseline

指定基线 TextDecoration

OverLine

指定超线 TextDecoration

Strikethrough

指定删除线 TextDecoration

Underline

指定下划线 TextDecoration

适用于