TextBlock Overview

The TextBlock control provides flexible text support for WPF applications. The element is targeted primarily toward basic UI scenarios that do not require more than one paragraph of text. It supports a number of properties that enable precise control of presentation, such as FontFamily, FontSize, FontWeight, TextEffects, and TextWrapping. Text content can be added using the Text property. When used in XAML, content between the open and closing tag is implicitly added as the text of the element.

For an explanation of all properties declared on TextBlock, see TextBlock Properties Sample.

A TextBlock element can be instantiated very simply using XAML.

<TextBlock FontSize="18" FontWeight="Bold" FontStyle="Italic">
  Hello, world!
</TextBlock>

Similarly, usage of the TextBlock element in code is relatively simple.

TextBlock myTextBlock = new TextBlock();
myTextBlock.FontSize = 18;
myTextBlock.FontWeight = FontWeights.Bold;
myTextBlock.FontStyle = FontStyles.Italic;
myTextBlock.Text = "Hello, world!";
Dim myTextBlock As New TextBlock()
myTextBlock.FontSize = 18
myTextBlock.FontWeight = FontWeights.Bold
myTextBlock.FontStyle = FontStyles.Italic
myTextBlock.Text = "Hello, world!"

Note: Label can be used as an alternative to TextBlock for situations where minimal text support is required such as the label for a control. Using Label can be advantageous because it requires even less resources (lighter weight) then a TextBlock.

See Also

Reference

Label

Other Resources

TextBlock Properties Sample