Export (0) Print
Expand All

TextBlock Content Model Overview

.NET Framework 3.5

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.

A TextBlock has the following content properties.

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.

Screenshot: TextBlocks  and buttons

Only TextBlock uses this content model.

Community Additions

ADD
Show:
© 2014 Microsoft