Share via


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.

Properties

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

Methods

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

Events

Loaded, MouseEnter, MouseLeave, MouseLeftButtonDown, MouseLeftButtonUp, MouseMove

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="https://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="https://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