2

I have a C# Windows Phone app that uses the ComponentOne RichTextBox control (C1RichTextBox). I need to do some post operations after inserting some text. The problem is, the inserted text is not visible in the control until some time in the future when the control has updated itself. If I try to do the operation directly after the insert, it fails because the inserted text is not yet visible in the Html property.

Does anyone know how to get a notification when the inserted text has been processed so I can do the post operation? In my use case, the post operation is highlighting the recently inserted text by changing the rich text box's selection to encompass it.

Here's the code I'm using. Note the comment I made about Exceptions occurring if I try to do the post operation immediately after the insert:

        if (insertionNdx >= rtbEdit.Text.Length)
            insertionNdx = rtbEdit.Text.Length - 1;

        rtbEdit.DocumentHistory.BeginGroup();

        switch (enInsertType)
        {
            case EnumInsertionType.eniText:
                rtbEdit.Text = rtbEdit.Text.Insert(insertionNdx, str);
                break;
            case EnumInsertionType.eniHtml:
                rtbEdit.Html = rtbEdit.Html.Insert(insertionNdx, str);
                break;
            default:
                throw new ArgumentOutOfRangeException("Unknown insertion type.");
        }

        rtbEdit.DocumentHistory.EndGroup();

        /* Can't do this here because the newly inserted content is not visible in the Html or Text
         *   property yet.  Worse, if the new text plus the insertion index is greater than the 
         *   length of the document, an Exception occurs because the selection range extends 
         *   beyond the end of the document.
        // Select the newly added text.
        rtbEdit.SelectionStart = insertionNdx;
        rtbEdit.SelectionLength = str.Length;

        rtbEdit.ScrollIntoView(rtbEdit.Selection.Start);
         */
Robert Oschler
  • 14,153
  • 18
  • 94
  • 227

0 Answers0