RichTextBox for UWP | ComponentOne
Working with C1Document Object / Implementing Split Views
In This Topic
    Implementing Split Views
    In This Topic

    Many editors offer split-views of a document, allowing you to keep a part of the document visible while you work on another part.

    You can achieve this easily by connecting two or more C1RichTextBox controls to the same underlying C1Document. Each control acts as an independent view, allowing you to scroll, select, and edit the document as usual. Changes made to one view are reflected on all other views.

    To show how this works, let's extend the previous example by adding a few lines of code to the page constructor:

    C#
    Copy Code
    // Add a second C1RichTextBox to the page
             LayoutRoot.RowDefinitions.Add(new RowDefinition());
             LayoutRoot.RowDefinitions.Add(new RowDefinition());
             var rtb2 = new C1RichTextBox();
             rtb2.SetValue(Grid.RowProperty, 1);
             LayoutRoot.Children.Add(rtb2);
    
             // Bind the second C1RichTextBox to the same document
             rtb2.Document = _rtb.Document;
    

     The new code adds a new C1RichTextBox to the page and then sets its C1RichTextBox.Document property to the document being shown by the original C1RichTextBox.

    If you run the project again, you will see that the bottom control is editable (we did not set its C1RichTextBox.IsReadOnly property to False). If you type into it, you will see the changes on both controls simultaneously.

    The mechanism is general; we could easily attach more views of the same document. Moreover, any changes you make to the underlying document are immediately reflected on all views.