This is a migrated thread and some comments may be shown as answers.

Inserting annotation ranges at the end of the document throws exception

1 Answer 24 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
juanjo
Top achievements
Rank 1
juanjo asked on 14 Feb 2014, 03:12 PM
[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

  











1 Answer, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 19 Feb 2014, 02:34 PM
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
Tags
RichTextBox
Asked by
juanjo
Top achievements
Rank 1
Answers by
Boby
Telerik team
Share this question
or