TextBlock 内容模型概述

更新:2007 年 11 月

此内容模型概述介绍了针对 TextBlock 的支持内容。TextBlock 是用于显示少量流内容的轻量控件。

本主题包括下列各节。

  • TextBlock 内容属性
  • 添加流内容
  • 共享此内容模型的类型
  • 可包含 TextBlock 对象的类型
  • 相关主题

TextBlock 内容属性

TextBlock 具有下列内容属性。

添加流内容

TextBlock 支持 Inline 流内容元素的承载和显示。 支持的元素包括 AnchoredBlockBoldHyperlinkInlineUIContainerItalicLineBreakRunSpanUnderline

下面的示例演示如何使用 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 使用此内容模型。

可包含 TextBlock 对象的类型

请参见 WPF 内容模型

请参见

概念

流文档概述