TextBlock Object

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

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


ActualHeight, ActualWidth, Canvas.Left, Canvas.Top, Canvas.ZIndex, Clip, Cursor, FontFamily, FontSize, FontStretch, FontStyle, FontWeight, Foreground, Height, Inlines, Name, Opacity, OpacityMask, RenderTransform, RenderTransformOrigin, Resources, Text, TextDecorations, TextWrapping, Tag, Triggers, Visibility, Width


AddEventListener, CaptureMouse, Equals, FindName, GetHost, GetParent, GetValue, ReleaseMouseCapture, RemoveEventListener, SetFontSource, SetValue


Loaded, MouseEnter, MouseLeave, MouseLeftButtonDown, MouseLeftButtonUp, MouseMove


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:

  <TextBlock>Hello, world!</TextBlock>

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.


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

  <TextBlock Text="Hello, world!" />

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