Blocks Property

RichTextBox.Blocks Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets the contents of the RichTextBox.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public BlockCollection Blocks { get; }
<RichTextBox ...>

XAML Values


Zero or more object elements for types that derive from Block. Typically, these are Paragraph elements.

Property Value

Type: System.Windows.Documents.BlockCollection
A BlockCollection that contains the contents of the RichTextBox.

The Blocks property is the content property of RichTextBox. It is a collection of Paragraph elements. Content in each Paragraph element can contain the following elements:

A InlineUIContainer can contain a UIElement, such as an Image or a Button.

A Span is a collection of Inline elements.

The following example shows how you can set content in a RichTextBox using XAML and code.

<!--A RichTextBox with intial content in it.-->
<RichTextBox VerticalScrollBarVisibility="Auto">
        A RichTextBox with <Bold>initial content</Bold> in it.

//A RichTextBox with intial content in it.
private void ContentRTB()
    //Create a new RichTextBox with its VerticalScrollBarVisibility property set to Auto.
    RichTextBox MyRTB = new RichTextBox();
    MyRTB.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;

    // Create a Run of plain text and some bold text.
    Run myRun1 = new Run();
    myRun1.Text = "A RichTextBox with ";
    Bold myBold = new Bold();
    myBold.Inlines.Add("initial content ");
    Run myRun2 = new Run();
    myRun2.Text = "in it.";

    // Create a paragraph and add the Run and Bold to it.
    Paragraph myParagraph = new Paragraph();

    // Add the paragraph to the RichTextBox.

    //Add the RichTextBox to the StackPanel.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

© 2018 Microsoft