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

Insert New Paragraph in Caret Position

1 Answer 159 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Ozan Bora
Top achievements
Rank 1
Ozan Bora asked on 05 Jul 2012, 10:53 PM
Hi,

I'm trying to insert a paragraph, which I want it to have a numbered item as well, to the caret position using Q3 2011 SP1. 
DocumentFragment is the only workaround that I found for the paragraph issue. But when I have numbered list in my document fragment it will be a different Document List as soon as I insert fragment to document. Consider the following example

originalParagraph.Inlines.Add(new Span("Numbered Item in Original Document"));
            originalNumberedList.AddParagraph(originalParagraph);
 
            originalSection.Blocks.Add(originalParagraph);
            originalSection.Blocks.Add(new Paragraph());
            originalDocument.Sections.Add(originalSection);
            originalDocument.CaretPosition.MoveToLastPositionInDocument();
 
            RadDocument documentFragment = new RadDocument();
            Section sectionFragment = new Section();
 
            NumberedList numberedListForFragment = new NumberedList(documentFragment);
            Paragraph paragraphFragment = new Paragraph();
 
            paragraphFragment.Inlines.Add(new Span("Numbered Item in Document Fragment"));
            numberedListForFragment.AddParagraph(paragraphFragment);
 
            sectionFragment.Blocks.Add(paragraphFragment);
            documentFragment.Sections.Add(sectionFragment);
 
            originalDocument.InsertFragment(new DocumentFragment(documentFragment));

If I use the same NumberedList defined for original document, Numbered List in original document is updated.

RadDocument originalDocument = new RadDocument();
            Section originalSection = new Section();
 
            NumberedList originalNumberedList = new NumberedList(originalDocument);
            Paragraph originalParagraph = new Paragraph();
 
            originalParagraph.Inlines.Add(new Span("Numbered Item in Original Document"));
            originalNumberedList.AddParagraph(originalParagraph);
 
            originalSection.Blocks.Add(originalParagraph);
            originalSection.Blocks.Add(new Paragraph());
            originalDocument.Sections.Add(originalSection);
            originalDocument.CaretPosition.MoveToLastPositionInDocument();
 
            RadDocument documentFragment = new RadDocument();
            Section sectionFragment = new Section();
 
            Paragraph paragraphFragment = new Paragraph();
 
            paragraphFragment.Inlines.Add(new Span("Numbered Item in Document Fragment"));
            originalNumberedList.AddParagraph(paragraphFragment);
 
            sectionFragment.Blocks.Add(paragraphFragment);
            documentFragment.Sections.Add(sectionFragment);
 
            originalDocument.InsertFragment(new DocumentFragment(documentFragment));

The thing is if I export and import the document using XamlFormatProvider the problem seems to be resolved. Is there any other workaround for this issue?

1 Answer, 1 is accepted

Sort by
0
Andrew
Telerik team
answered on 10 Jul 2012, 04:30 PM
Hi Ozan,

Using both approaches you described when the fragment is inserted, two paragraphs are created that are part of the same list (numbered 1 and 2). You can see the screenshot attached. If that is not what you expect, please elaborate a little bit more on what your expected result is (and send screenshot if possible).

All the best,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Ozan Bora
Top achievements
Rank 1
Answers by
Andrew
Telerik team
Share this question
or