Suspend Update

4 posts, 0 answers
  1. Scott Michetti
    Scott Michetti avatar
    112 posts
    Member since:
    Feb 2010

    Posted 20 May 2014 Link to this post

    Hello, does the RichTextBox have a method that will prevent the UI updating while I change the text in code? At times, some of the updates I make don't show up in the UI, and I'm thinking it's a timing or refresh issue. I'm editing the existing text. Sometimes the font won't change, sometimes the alignment won't change etc. My code looks something  like this:

    radRichText.Background = new SolidColorBrush((Color)ViewModel.TextBackColor);           
    FontFamily fontFamily = new System.Windows.Media.FontFamily(ViewModel.Font);

  2. Petya
    Petya avatar
    990 posts

    Posted 21 May 2014 Link to this post

    Hello Scott,

    There are cases when such issues might occur, for example if you modify the document elements in a measured document directly. For example, if a document is shown in RadRichTextBox and you use the collections to obtain a Span element in it and change its Text property like in this snippet:
    //DO NOT use this code
    Span someSpan = (this.radRichTextBox.Document.Sections.First.Blocks.First as Paragraph).Inlines.First as Span;
    someSpan.Text = "changed text";

    More information about the two states of a document is available here and this article explains what to do in case you want to modify the contents of a measured document.

    I'm having troubles determining the state of the document you are manipulating and the approach you are using based on your post, but please note that it is usually recommended to utilize RadRichTextBox or RadDocumentEditor for any document changes.

    I hope this helps.

    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
  3. Wai
    Wai avatar
    1 posts
    Member since:
    Jul 2014

    Posted 03 Jan 2015 Link to this post


    I am having this exact same problem. When I update the text of a span or span box, the change does not appear on the richtextbox right away. It appears after I hit another key. I need to be able to insert some text at the location of the cursor. Could you suggest another way of doing it? The cursor has to stay at the same location. I am doing this currently.

                        DocumentPosition startPosition = this.Editor.Document.CaretPosition; 
                        var text = startPosition.GetPreviousSpanBox();
                        text.AssociatedSpan.Text += "some text";


  4. Petya
    Petya avatar
    990 posts

    Posted 07 Jan 2015 Link to this post

    Hello Wai,

    Like I've said in my previous reply, directly changing any DocumentElement in a measured document is not recommended and could cause the behavior you are observing, as well as unexpected crashes.

    As far as I can tell from the code snippet in your post, you are trying to insert specific content directly after the span where the caret is located, could you confirm? Please note that a Span element does not always correspond to a single word. For example, the following: ABCDEF would be split into two separate spans because the characters have different styling.

    As to retaining the caret position while executing actions, you can try an approach similar to the one from this forum thread. Create a custom annotation marker and insert it at the caret position on demand, in the case of the demo when exporting and in yours - just before editing the string. Then move the caret to the desired location in order to insert the text, e.g. this snippet inserts at the end of the current word:
    this.radRichTextBox.Insert("some text");

    I hope this is useful.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top