TextBlock.Text 属性

定义

获取或设置 TextBlock 的文本内容。Gets or sets the text contents of a TextBlock.

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
[System.Windows.Localizability(System.Windows.LocalizationCategory.Text)]
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

属性值

TextBlock 的文本内容。The text contents of this TextBlock. 注意,所有非文本内容将被剥除,从而获得 TextBlock 内容的纯文本表示。Note that all non-text content is stripped out, resulting in a plain text representation of the TextBlock contents. 默认值为 EmptyThe default is Empty.

属性

示例

下面的示例演示如何设置 TextBlock 元素的 Text 特性。The following example shows how to set the Text attribute of a TextBlock element.

<TextBlock Text="The text contents of this TextBlock element."/>

或者,文本运行的内容可能只包含 TextBlock 元素标记中。Alternately, the contents of a text run may simply be contained by TextBlock element tags.

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

TextBlock textBlock = new TextBlock();
textBlock.Text = "The text contents of this TextBlock.";
Dim textBlock As New TextBlock()
textBlock.Text = "The text contents of this TextBlock."

注解

如果要在 TextBlock中显示纯文本,请使用此属性。Use this property when you want to show plain text in a TextBlock. 需要设置文本的格式时,请向 Inlines 属性添加 Inline 对象。When you need to format the text, add Inline objects to the Inlines property.

依赖项属性信息Dependency Property Information

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

适用于