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.

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!"

See also