TextDecorations 类

定义

提供一组静态预定义文本修饰。Provides a set of static predefined text decorations.

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

示例

在下面的示例中,删除线文本修饰使用默认字体值。In the following example, a strikethrough text decoration uses the default font value.

// 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>

还可以为同一文本指定多个文本修饰。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>

您可以使用字符串值 "None" 指示集合中没有文本修饰 TextDecorationsYou can use the string value "None" to indicate that there are no text decorations in the TextDecorations collection. 在下面的示例中,将 TextDecorations 集合设置为 "None"。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>

您可以使用方法从文本中删除所有文本修饰 ClearYou can remove all text decorations from text by using the Clear method. 在下面的示例中, TextDecorations 清除了集合。In the following example, the TextDecorations collection is cleared.

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

默认情况下, Hyperlink 使用 TextDecoration 对象显示下划线。By default, Hyperlink uses a TextDecoration object to display an underline. 以下标记示例显示了 Hyperlink 使用和不带下划线定义的: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 实例化对象的性能可能会很高,尤其是在有多个对象的情况下 HyperlinkTextDecoration 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.

注解

有四种类型的文本修饰:基线、上划线、删除线和下划线。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 属性用法XAML Attribute Usage

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

XAML 值XAML Values

textDecorationType
文本修饰的类型: BaselineOverLineStrikethroughUnderlineThe type of text decoration: Baseline, OverLine, Strikethrough, or Underline. 允许使用多个修饰,其值用逗号分隔。More than one decoration is permitted, with values separated by commas. 您还可以指定 "None",以指示没有文本修饰类型。You can also specify "None" to indicate no type of text decoration.

属性

Baseline

指定一个基线 TextDecorationSpecifies a baseline TextDecoration.

OverLine

指定一个上划线 TextDecorationSpecifies an overline TextDecoration.

Strikethrough

指定一个删除线 TextDecorationSpecifies a strikethrough TextDecoration.

Underline

指定一个下划线 TextDecorationSpecifies an underline TextDecoration.

适用于