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 Attribute Usage

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

XAML 值

textDecorationType
文字裝飾的類型: BaselineOverLineStrikethroughUnderline 。 允許多個裝飾,並以逗號分隔值。 您也可以指定 「None」 來表示沒有類型的文字裝飾。

屬性

Baseline

指定基準線 TextDecoration

OverLine

指定頂線 TextDecoration

Strikethrough

指定刪除線 TextDecoration

Underline

指定底線 TextDecoration

適用於