Edit

Share via


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

See also


Additional resources

Documentation

  • TextBox Styles and Templates - WPF

    Learn about styles and templates for the Windows Presentation Foundation TextBox control. Modify the ControlTemplate to give the control a unique appearance.

  • TextBox Overview - WPF

    Overview of how the TextBox class enables you to display or edit unformatted text in Windows Presentation Foundation (WPF) applications.

  • Panels Overview - WPF

    Windows Presentation Foundation provides predefined Panel elements that control the rendering of elements. Learn how to construct custom Panel elements.

  • How to: Use a Grid for Automatic Layout - WPF

    Learn how to use a grid for automatic layout when creating an application that is localization ready.