Skip to main content
Version: 11.0.x

SelectableTextBlock

The SelectableTextBlock block is a label for the display of text that allows selecting and copying 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
SelectionStarta character index for the start of the current selection.
SelectionEnda character index for the end of the current selection.
SelectionBrushThe brush that highlights selected text.
SelectionForegroundBrush that is used for the foreground of selected text.
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">
<SelectableTextBlock Margin="0 5" FontSize="18" FontWeight="Bold" >Heading</SelectableTextBlock>
<SelectableTextBlock Margin="0 5" FontStyle="Italic" xml:space="preserve" SelectionBrush="Red">This is a single line.</SelectableTextBlock>
<SelectableTextBlock Margin="0 5" xml:space="preserve" SelectionStart="3" SelectionEnd="13">This is a multi-line display
that has returns in it.
The text block respects the line breaks
as set out in XAML.</SelectableTextBlock>
</StackPanel>

The styling works in the preview pane:

More Information

info

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

info

View the source code on GitHub SelectableTextBlock.cs