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();
          roEnd1.PairWithStart(roStart);

          _editor.InsertInline(roStart);
          _editor.InsertInline(new Span("READONLY"));
          _editor.InsertInline(roEnd);
          _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?

    Thanks,

    Juanjo

      











  2. Boby
    Admin
    Boby avatar
    595 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");
    _editor.InsertInline(span);
     
    DocumentPosition startPosition = new DocumentPosition(_editor.Document);
    startPosition.MoveToInline(span);
    DocumentPosition endPosition = new DocumentPosition(_editor.Document.CaretPosition);
     
    _editor.Document.Selection.SetSelectionStart(startPosition);
    _editor.Document.Selection.AddSelectionEnd(endPosition);
     
    _editor.InsertReadOnlyRange();
     
    _editor.Insert(" some more text");
    Don't hesitate to contact us if you have other questions.

    Regards,
    Boby
    Telerik
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top