Share via


TextBlock.TextDecorations 屬性

定義

取得或設定 TextDecorationCollection,其中包含要套用至 TextBlock 之文字的效果。

public:
 property System::Windows::TextDecorationCollection ^ TextDecorations { System::Windows::TextDecorationCollection ^ get(); void set(System::Windows::TextDecorationCollection ^ value); };
public System.Windows.TextDecorationCollection TextDecorations { get; set; }
member this.TextDecorations : System.Windows.TextDecorationCollection with get, set
Public Property TextDecorations As TextDecorationCollection

屬性值

TextDecorationCollection

TextDecorationCollection 集合,包含要套用至這個項目的文字裝飾。 預設值為 null (不套用文字裝飾)。

範例

下列範例示範如何設定 TextDecorations 屬性。

<TextBlock TextDecorations="Strikethrough">
  This text will render with the strikethrough effect.
</TextBlock>

下圖顯示此範例的轉譯方式。

螢幕擷取畫面:套用預設刪除線效果的文字

下圖顯示 、 BaselineUnderline 裝飾如何 OverLine 分別呈現。

螢幕擷取畫面:頂線 TextDecorator

螢幕擷取畫面:對文字套用的預設基準線效果

螢幕擷取畫面:套用預設底線效果的文字

下列範例示範如何以程式設計方式設定 TextDecorations 屬性。

TextBlock textBlock = new TextBlock(new Run("This text will render with the strikethrough effect."));
textBlock.TextDecorations = TextDecorations.Strikethrough;
Dim textBlock As New TextBlock(New Run("This text will render with the strikethrough effect."))
textBlock.TextDecorations = TextDecorations.Strikethrough

備註

TextDecoration物件是您可以新增至文字的視覺裝飾。 文字裝飾有四種類型:底線、基準、刪除線和超線。 如需文字裝飾的詳細資訊,請參閱 如何:建立文字裝飾

根據預設,此屬性會設定為 null ,且沒有 TextDecorationCollection 與其建立關聯的屬性。 新增任何文字效果之前,請先建立新的 TextDecorationCollection ,並將它指派給這個屬性。

相依性屬性資訊

識別碼欄位 TextDecorationsProperty
設定為 的中繼資料屬性 true AffectsRender

適用於