How to replace all inlineUIContainers in RadDocument by SpanBoxs

3 posts, 0 answers
  1. york
    york avatar
    160 posts
    Member since:
    Jul 2012

    Posted 20 Jan 2013 Link to this post

    Hi,
    I try to replace all inlineUIContainers in RadDocument by SpanBoxes. I know how to do it at caretposition using Delete as,
    DocumentPosition currentPosition = radRichTextBox1.Document.CaretPosition;
    radRichTextBox1.Document.Delete(false, currentPosition);
    radRichTextBox1.Insert(text);

    However I am not sure how to get documentpostion for each inlineUIContainers. I need help on this.

    Thanks,
    York
  2. Christian
    Christian avatar
    1 posts
    Member since:
    Aug 2011

    Posted 14 Jun 2013 Link to this post

    Did you figure this out?
    I need help for the exact same problem...
  3. UI for WPF is Visual Studio 2017 Ready
  4. Boby
    Admin
    Boby avatar
    595 posts

    Posted 19 Jun 2013 Link to this post

    Hello Christian, York,
    You can achieve this as follows:
    this.radRichTextBox.BeginUndoGroup();
     
    foreach (var inlineUIContainer in this.radRichTextBox.Document.EnumerateChildrenOfType<InlineUIContainer>().Reverse().ToList())
    {
        this.radRichTextBox.Document.CaretPosition.MoveToStartOfDocumentElement(inlineUIContainer);
        this.radRichTextBox.Delete(false);
        this.radRichTextBox.InsertInline(new Span("InlineUIContainer was here."));
    }
     
    this.radRichTextBox.EndUndoGroup("Replace all InlineUIContainers");
    The trick is to iterate the document elements in reversed order to avoid invalidating of the internal document indexes.

    Regards,
    Boby
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top