New to Telerik UI for WPF? Download free 30-day trial

Span

The Span class represents an inline object that allows you to display formatted text. The Spans can only be used in the context of a Paragraph class. As the spans are inline elements they get placed one after another and the text inside them gets wrapped to the next line if the space is insufficient.

This topic will explain you how to:

Use Spans

The Spans can be used only in the context of the Paragraph element. The Paragraph exposes a collection of Inlines, to which the spans can be added. This can also be done directly in XAML.

<telerik:RadRichTextBox x:Name="radRichTextBox"> 
    <telerik:RadDocument> 
        <telerik:Section> 
            <telerik:Paragraph> 
                <telerik:Span Text="Span declared in XAML" /> 
            </telerik:Paragraph> 
        </telerik:Section> 
    </telerik:RadDocument> 
</telerik:RadRichTextBox> 

Section section = new Section(); 
Paragraph paragraph = new Paragraph(); 
Span span = new Span("Span declared in code-behind"); 
paragraph.Inlines.Add( span ); 
section.Blocks.Add( paragraph ); 
this.radRichTextBox.Document.Sections.Add( section ); 
Dim section As New Section() 
Dim paragraph As New Paragraph() 
Dim span As New Span("Span declared in code-behind") 
paragraph.Inlines.Add(span) 
section.Blocks.Add(paragraph) 
Me.radRichTextBox.Document.Sections.Add(section) 

Add Text to a Span

To specify the text in the Span you can use its Text property.

<telerik:Span Text="Thank you for choosing Telerik RadRichTextBox!" /> 

Span span = new Span(); 
span.Text = "Thank you for choosing Telerik RadRichTextBox!"; 
Dim span As New Span() 
span.Text = "Thank you for choosing Telerik RadRichTextBox!" 

Customize a Span

The Span exposes several properties that allow you to customize the layout of the elements placed underneath it. Here is a list of them:

  • BaselineAlignment - indicates whether the text is Baseline, Subscript or Superscript.

  • FontFamily - represents the name of the text's font.

  • FontSize - represent the size of the text.

  • FontStyle - indicates whether the text should have its style set to italic or to normal.

  • FontWeight - represents the value for the text's weight.

  • ForeColor - represents the foreground color for the text.

  • HighlightColor - represents the background color for the text.

  • Strikethrough - indicates whether the text should be stroke through.

  • UnderlineDecoration - indicates whether the text should be underlined.

See Also

In this article