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 屬性。

相依性屬性資訊

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

適用於