TextBlock Content Model Overview
This content model overview describes the supported content for a TextBlock. A TextBlock is a lightweight control for displaying small amounts of flow content.
This topic contains the following sections.
- TextBlock Content Property
- Adding Flow Content
- Types That Share This Content Model
- Types That Can Contain TextBlock Objects
- Related Topics
TextBlock Content Property
A TextBlock has the following content properties.
Adding Flow Content
TextBlock supports the hosting and display of Inline flow content elements. Supported elements include AnchoredBlock, Bold, Hyperlink, InlineUIContainer, Italic, LineBreak, Run, Span, and Underline.
The following example shows how to use the Inlines property to add flow elements to a 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.";
The following figure shows how this example renders.
Types That Share This Content Model
Only TextBlock uses this content model.
Types That Can Contain TextBlock Objects
See WPF Content Model.