Gets or sets the horizontal alignment characteristics that are applied to a FrameworkElement when it is composed in a layout parent, such as a panel or items control. (Inherited from FrameworkElement.)

Gets or sets the identifying name of the object. When a XAML processor creates the object tree from XAML markup, run-time code can refer to the XAML-declared object by this name. (Inherited from FrameworkElement.)

Adds a routed event handler for a specified routed event, adding the handler to the handler collection on the current element. Specify handledEventsToo as true to have the provided handler be invoked for routed event that had already been marked as handled by another element along the event route. (Inherited from UIElement.)

Positions child objects and determines a size for a UIElement. Parent objects that implement custom layout for their child elements should call this method from their layout override implementations to form a recursive layout update. (Inherited from UIElement.)

Updates the DesiredSize of a UIElement. Typically, objects that implement custom layout for their layout children call this method from their own MeasureOverride implementations to form a recursive layout update. (Inherited from UIElement.)

When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in an application. For more information, see Remarks. (Inherited from FrameworkElement.)

Occurs when the left mouse button is released (or the tip of the stylus is removed from the tablet) while the mouse (or the stylus) is over a UIElement (or while a UIElement holds mouse capture). (Inherited from UIElement.)

Occurs when the right mouse button is released while the mouse pointer is over a UIElement. However, this event will only be raised if a caller marks the preceding MouseRightButtonDown event as handled; see Remarks. (Inherited from UIElement.)

The TextBlock control is the primary element for displaying text in Silverlight based applications. If you need to display caption for another control that includes required field or validation error indicators, use the Label control.

When you set text in a TextBlock, it is not necessary in XAML to explicitly specify the Text property. You can put text in the TextBlock container as its content, or inner text, as in the following example:

The Run and LineBreak objects can also be used to render formatted text, as child elements of a TextBlock in XAML (or as items of Inlines in code). 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.

The default value of the FontSize property of a rendered TextBlock is 11 (measured in pixels).

The default value of the FontFamily property of a rendered TextBlock is "Portable User Interface". For more information on the "Portable User Interface" concept, see Text and Fonts.

TextBlock Text Model

Rather than presenting a single string, a TextBlock can also present a series of strings contained in different Run elements, where each element can have different character-level font attributes. The LineBreak object represents an explicit new line in a TextBlock, and is generally used between surrounding Run elements. LineBreak and Run share a base class (Inline), which makes it possible for a TextBlock to hold a strongly typed InlineCollection of its text model content. That InlineCollection is also the TextBlock XAML content property, and the end result is that to specify items in the TextBlock model you simply specify various Run and LineBreak elements as child elements of the TextBlock.

The following XAML example shows how to define several differently formatted text strings in a TextBlock by using Run objects, separated with LineBreak.

The following illustration shows the rendered formatted text from the previous XAML content example.

TextBlock rendering multiple Run objects

LineBreak forces the text in each Run to display on a separate line. Without the LineBreak, the text in each Run would flow together as one line and would often be clipped due to exceeding the TextBlock object width or the width of the Silverlight content area. The following illustration shows how the formatted text would render without using LineBreak objects.

TextBlock rendering multiple Run objects without LineBreak objects

Accessing the TextBlock Text Model in Code

There are really two properties involved in the TextBlock text model: Text, and Inlines. Changing the value of Text is not always advisable, because it can flatten any existing font element formatting on the individual Run items as well as strip the LineBreak elements for a TextBlock that was originally constructed with inlines and not just Text. For details, see Inlines.