通过


TextBlock.Text 属性

定义

获取或设置一个 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; }
[<System.Windows.Localizability(System.Windows.LocalizationCategory.Text)>]
member this.Text : string with get, set
Public Property Text As String

属性值

此文本内容 TextBlock。 请注意,将去除所有非文本内容,从而产生内容的 TextBlock 纯文本表示形式。 默认值为 Empty

属性

示例

以下示例演示如何设置 Text 元素的属性 TextBlock

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

或者,文本运行的内容可能只是由 TextBlock 元素标记包含。

以下示例演示如何以编程方式设置 Text 属性。

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显示纯文本,请使用此属性。 需要设置文本格式时,请将对象添加到InlineInlines属性。

Dependency 属性信息

物品 价值
标识符字段 TextProperty
元数据属性设置为 true AffectsMeasureAffectsRender

适用于