TextBlock 內容模型概觀
更新:2007 年 11 月
本內容模型概觀說明 TextBlock 支援的內容。TextBlock 是一種適合顯示少量非固定格式內容的輕量控制項。
這個主題包含下列章節。
- TextBlock 內容屬性
- 加入非固定格式內容
- 共用此內容模型的型別
- 可以包含 TextBlock 物件的型別
- 相關主題
TextBlock 內容屬性
TextBlock 具有下列內容屬性。
加入非固定格式內容
TextBlock 可支援 Inline 非固定格式內容項目的裝載和顯示。支援的項目包括 AnchoredBlock、Bold、Hyperlink、InlineUIContainer、Italic、LineBreak、Run、Span 和 Underline。
下列範例顯示如何使用 Inlines 屬性將非固定格式內容項目加入至 TextBlock。
TextBlock textBlock1 = new TextBlock();
TextBlock textBlock2 = new TextBlock();
textBlock1.TextWrapping = textBlock2.TextWrapping = TextWrapping.Wrap;
textBlock2.Background = Brushes.AntiqueWhite;
textBlock2.TextAlignment = TextAlignment.Center;
textBlock1.Inlines.Add(new Bold(new Run("TextBlock")));
textBlock1.Inlines.Add(new Run(" is designed to be "));
textBlock1.Inlines.Add(new Italic(new Run("lightweight")));
textBlock1.Inlines.Add(new Run(", and is geared specifically at integrating "));
textBlock1.Inlines.Add(new Italic(new Run("small")));
textBlock1.Inlines.Add(new Run(" portions of flow content into a UI."));
textBlock2.Text =
"By default, a TextBlock provides no UI beyond simply displaying its contents.";
下圖顯示這個範例呈現的樣子。
共用此內容模型的型別
只有 TextBlock 會使用這個內容模型。
可以包含 TextBlock 物件的型別
請參閱 WPF 內容模型。