When I select a single line(See screenshot 1) and convert into an annotation range using InsertFragment, it is getting inserted. (See screenshot 2).
But, when I select multiple lines(See screenshot 3), InsertFragment is not working.
Code Sample:
RadDocument associatedDocument = associatedRichTextBox.Document;
DocumentSelection selection = associatedDocument.Selection;
DocumentPosition documentPosition = associatedDocument.CaretPosition;
string selectedText = GetSelectedText(associatedDocument);
RadDocument tempDocument = new RadDocument();
Section section = new Section();
Paragraph paragraph = new Paragraph();
try
{
//BookmarkRangeStart bookmarkRangeStart = new BookmarkRangeStart();
//BookmarkRangeEnd bookmarkRangeEnd = new BookmarkRangeEnd();
//bookmarkRangeEnd.PairWithStart(bookmarkRangeStart);
//paragraph.Inlines.Add(bookmarkRangeStart);
//paragraph.Inlines.Add(bookmarkRangeEnd);
HeadingRangeStart headingRangeStart = new HeadingRangeStart();
HeadingRangeEnd headingRangeEnd = new HeadingRangeEnd();
headingRangeEnd.PairWithStart(headingRangeStart);
Span spanSelectedText = new Span(selectedText.TrimEnd());
spanSelectedText.FontWeight = FontWeights.Bold;
spanSelectedText.ForeColor = Colors.Red;
paragraph.Inlines.Add(headingRangeStart);
paragraph.Inlines.Add(spanSelectedText);
paragraph.Inlines.Add(headingRangeEnd);
section.Blocks.Add(paragraph);
tempDocument.Sections.Add(section);
tempDocument.MeasureAndArrangeInDefaultSize();
tempDocument.Selection.SelectAll();
associatedRichTextBox.UpdateEditorLayout();
associatedRichTextBox.InsertFragment(tempDocument.Selection.CopySelectedDocumentElements(true));
associatedRichTextBox.Document.Selection.Clear();
associatedRichTextBox.UpdateEditorLayout();
}
Please suggest a solution.
But, when I select multiple lines(See screenshot 3), InsertFragment is not working.
Code Sample:
RadDocument associatedDocument = associatedRichTextBox.Document;
DocumentSelection selection = associatedDocument.Selection;
DocumentPosition documentPosition = associatedDocument.CaretPosition;
string selectedText = GetSelectedText(associatedDocument);
RadDocument tempDocument = new RadDocument();
Section section = new Section();
Paragraph paragraph = new Paragraph();
try
{
//BookmarkRangeStart bookmarkRangeStart = new BookmarkRangeStart();
//BookmarkRangeEnd bookmarkRangeEnd = new BookmarkRangeEnd();
//bookmarkRangeEnd.PairWithStart(bookmarkRangeStart);
//paragraph.Inlines.Add(bookmarkRangeStart);
//paragraph.Inlines.Add(bookmarkRangeEnd);
HeadingRangeStart headingRangeStart = new HeadingRangeStart();
HeadingRangeEnd headingRangeEnd = new HeadingRangeEnd();
headingRangeEnd.PairWithStart(headingRangeStart);
Span spanSelectedText = new Span(selectedText.TrimEnd());
spanSelectedText.FontWeight = FontWeights.Bold;
spanSelectedText.ForeColor = Colors.Red;
paragraph.Inlines.Add(headingRangeStart);
paragraph.Inlines.Add(spanSelectedText);
paragraph.Inlines.Add(headingRangeEnd);
section.Blocks.Add(paragraph);
tempDocument.Sections.Add(section);
tempDocument.MeasureAndArrangeInDefaultSize();
tempDocument.Selection.SelectAll();
associatedRichTextBox.UpdateEditorLayout();
associatedRichTextBox.InsertFragment(tempDocument.Selection.CopySelectedDocumentElements(true));
associatedRichTextBox.Document.Selection.Clear();
associatedRichTextBox.UpdateEditorLayout();
}
Please suggest a solution.