次の方法で共有


TextBlock

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents a lightweight object for displaying single-line and multiple-line text with multiple format options.

<TextBlock   .../>

Properties

ActualHeight (UIElement), ActualWidth (UIElement), Canvas.Left, Canvas.Top, Canvas.ZIndex, Clip, Cursor, Effect (Silverlight 3), FontFamily, FontSize, FontStretch, FontStyle, FontWeight, Foreground, Grid.Column (Silverlight 2), Grid.ColumnSpan (Silverlight 2), Grid.Row (Silverlight 2), Grid.RowSpan (Silverlight 2), Height (UIElement), HorizontalAlignment (Silverlight 2), Inlines (TextBlock), Language (Silverlight 2), LineHeight (Silverlight 2), LineStackingStrategy (Silverlight 2), Margin (Silverlight 2), MaxHeight (Silverlight 2), MaxWidth (Silverlight 2), MinHeight (Silverlight 2), MinWidth (Silverlight 2), Name (DependencyObject), Opacity (UIElement), OpacityMask, Padding (Silverlight 2), Projection (Silverlight 3), RenderTransform, RenderTransformOrigin, Resources, Style (Silverlight 2), Text (TextElement), TextAlignment (Silverlight 2), TextDecorations, TextOptions.TextHintingMode (Silverlight 3), TextWrapping, Tag, Triggers, VerticalAlignment, Visibility, Width (UIElement)

Managed Equivalent

TextBlock

Remarks

The TextBlock object is the primary element for displaying read-only text in Silverlight applications using the JavaScript API.

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.

In XAML, you do not need to explicitly specify the Text property when you set text in a TextBlock. You can use the intuitive markup syntax of placing text in the TextBlock container as its content, or inner text, as shown in the following example:

<Canvas
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <TextBlock>Hello, world!</TextBlock>
</Canvas>
NoteNote:

Any leading or trailing whitespace is not preserved when you set the Text property.

You can also use the Run and LineBreak objects to render or format 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 basic concepts, see Text and Fonts. Note that the Text and Fonts topic is written primarily for users of the managed API, and may not have code examples or specific information that address the JavaScript API scenarios.

Example

The following example shows how to define a TextBlock element and set its Text (TextElement) property to a character string.

<Canvas
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <TextBlock Text="Hello, world!" />
</Canvas>

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

TextBlock rendering with default font properties

"Hello, world!" textblock.

See Also

Reference

Run