Inserting annotation ranges at the end of the document throws exception

2 posts, 0 answers
  1. juanjo
    juanjo avatar
    3 posts
    Member since:
    Aug 2011

    Posted 14 Feb 2014 Link to this post

    [WPF Rad Controls Version 2013.3.1016.40]

    The following code thrwos an InvalidCastException exception when the caret is at the end of the Document:

    void DoIt()
          var roStart = new ReadOnlyRangeStart();
          var roEnd = new ReadOnlyRangeEnd();

          _editor.InsertInline(new Span("READONLY"));
          _editor.Insert(" some more text");

    We can workaround this behavior inserting a new char at the end of the doc, move back the caret and finally removing the extra char.
    Is this the expected behavior?
    If not, is the last version fixing this problem?




  2. Boby
    Boby avatar
    763 posts

    Posted 19 Feb 2014 Link to this post

    Hello Juanjo,
    Annotations (read-only ranges in your case) have to be inserted using the specific methods for this purpose. For example, in your case this should work as expected:
    var span = new Span("READONLY");
    DocumentPosition startPosition = new DocumentPosition(_editor.Document);
    DocumentPosition endPosition = new DocumentPosition(_editor.Document.CaretPosition);
    _editor.Insert(" some more text");
    Don't hesitate to contact us if you have other questions.

Back to Top