跳到主要内容
版本:11.0.0

Text Block

The text block is a read-only label for the display of text. It can display multiple lines, and features full control over the font used.

Useful Properties

You will probably use these properties most often:

PropertyDescription
FontSizeThe size of the font.
FontWeightThe weight of the font. Default is normal, options include Bold.
FontStyleA style to apply to the lettering. Default is normal, options include Italic.
TextDecorationsA line decoration to apply to the lettering. Default is none, options include Underline, Strikethrough, Baseline and Overline. To apply more than one at the same time, list the options with spaces between.
xml:spaceTextBlock itself would respect the line breaks and whitespace of its content as set out in XAML, but it will be filtered out by the parser without xml:space="preserve".

Example

This example shows a text block used as a heading, single line and multi-line displays.

<StackPanel Margin="20">
<TextBlock Margin="0 5" FontSize="18" FontWeight="Bold">Heading</TextBlock>
<TextBlock Margin="0 5" FontStyle="Italic" xml:space="preserve">This is a single line.</TextBlock>
<TextBlock Margin="0 5" xml:space="preserve">This is a multi-line display
that has returns in it.
The text block repects the line breaks
as set out in XAML.</TextBlock>
</StackPanel>

The styling works in the preview pane:

More Information

信息

For the complete API documentation about this control, see here.

信息

View the source code on GitHub TextBlock.cs