Export (0) Print
Expand All

TextBlock Object

Represents a lightweight object for displaying single-line and multi-line multi-formatted text.

XAML
<TextBlock .../>
Scripting
To create an object using scripting, see CreateFromXAML.

Remarks

The TextBlock object is the primary element for displaying text in Silverlight applications.

The default value of the FontSize property of a rendered TextBlock is 14.666 pixels, which is exactly 11 points.

The default value of the FontFamily property of a rendered TextBlock is "Lucida Sans Unicode, Lucida Grande". Application-served fonts are not required to enable the default font.

When setting text in a TextBlock, it is not necessary in XAML to explicitly specify the Text property; you can use the intuitive markup syntax of placing text within the TextBlock container as its content, or inner text:

XAML
<Canvas
  xmlns="http://schemas.microsoft.com/client/2007">
  <TextBlock>Hello, world!</TextBlock>
</Canvas>

Note   Any leading or trailing whitespace is not preserved when setting the Text property.

The Run and LineBreak objects can also be used to render text. The Run object is a text element that represents a discrete section of formatted or unformatted text. The LineBreak object represents an explicit new line in a TextBlock. For more information on using a TextBlock and formatting text, see Text and Fonts Overview.

Examples

>The following XAML example shows how to define a TextBlock element and set its Text property to a character string:

XAML
<Canvas
  xmlns="http://schemas.microsoft.com/client/2007">
  <TextBlock Text="Hello, world!" />
</Canvas>

The following illustration displays the result of the previous XAML content example.

TextBlock rendering with default font properties

TextBlock rendering with default font properties

See Also

Text and Fonts Overview
Run
LineBreak

Community Additions

Show:
© 2015 Microsoft