TextBlock.TextDecorations Property


获取或设置 TextDecorationCollection,它包含应用于 TextBlock 的文本的效果。Gets or sets a TextDecorationCollection that contains the effects to apply to the text of a TextBlock.

 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

Property Value


一个 TextDecorationCollection 集合,它包含应用于此元素的文本修饰。A TextDecorationCollection collection that contains text decorations to apply to this element. 默认值为 null(不应用任何文本修饰)。The default is null (no text decorations applied).


下面的示例演示如何设置 TextDecorations 特性。The following example shows how to set the TextDecorations attribute.

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

下图显示了此示例的呈现效果。The following figure shows how this example renders.

屏幕快照:具有默认删除线效果的文本Screenshot: Text with default strikethrough effect

下图显示了 OverLineBaselineUnderline 修饰的分别呈现方式。The following figures show how the OverLine, Baseline, and Underline decorations render, respectively.

屏幕截图:上划线 TextDecoratorScreenshot: Overline TextDecorator

屏幕快照:文本上的默认基线效果Screenshot: Default baseline effect on text

屏幕快照:具有默认下划线效果的文本Screenshot: Text with default underline effect

下面的示例演示如何以编程方式设置 TextDecorations 属性。The following example shows how to set the TextDecorations property programmatically.

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 对象是可以添加到文本的视觉对象装饰。A TextDecoration object is a visual ornamentation you can add to text. 有四种类型的文本修饰:下划线、基线、删除线和上划线。There are four types of text decorations: underline, baseline, strikethrough, and overline. 有关文本修饰的详细信息,请参阅如何:创建文本修饰For more information about text decorations, see How to: Create a Text Decoration.

默认情况下,此属性设置为 "null",并且没有任何与之关联的 TextDecorationCollectionBy default, this property is set to null and has no TextDecorationCollection associated with it. 在添加任何文本效果之前,请创建新的 TextDecorationCollection 并将其分配给此属性。Before adding any text effects, create a new TextDecorationCollection and assign it to this property.

依赖项属性信息Dependency Property Information

标识符字段Identifier field TextDecorationsProperty
元数据属性设置为 trueMetadata properties set to true AffectsRender

Applies to