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

Paragraph Runs Not Linked to Parent

2 Answers 19 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Bart
Top achievements
Rank 1
Bart asked on 21 Apr 2018, 10:09 PM

If I am using this:

public sealed class Document
{
    public Document(string header, string content)
    {
        Heading = header;
        Content = content;
    }
 
    public string Heading { get; set; }
    public string Content { get; set; }
}

 

And this collection

public List<Document> Documents { get; }

And this document Implementation

public void Create(RadFlowDocument document)
{
    var editor = new RadFlowDocumentEditor(document);

 

    foreach (var t in Documents)
    {
        if (t.Content == null || t.Heading == null) continue;
        var section = document.Sections.AddSection();
        section.SectionType = SectionType.Continuous;
        var paragraph = section.Blocks.AddParagraph();
        editor.MoveToParagraphStart(paragraph);
        paragraph.StyleId = BuiltInStyleNames.GetHeadingStyleIdByIndex(1);
        paragraph.Inlines.AddRun(t.Heading).Paragraph.Inlines.AddRun();

        //is it this next line, because I am making a new paragraph?

        section.Blocks.AddParagraph().Inlines.AddRun(t.Content);
    }
}

 

Everything generates great, but if I am in Word, and collapse one of t.Heading... The t.Content does not collapse under it.  How can I add t.Heading that uses the default word style of 1 (Heading 1) and the text under it use Normal and expand and collapse with the Heading? 

2 Answers, 1 is accepted

Sort by
0
Bart
Top achievements
Rank 1
answered on 21 Apr 2018, 10:14 PM

Had a copy error:

This line:

paragraph.Inlines.AddRun(t.Heading).Paragraph.Inlines.AddRun();

 

Should be:

paragraph.Inlines.AddRun(t.Heading);
0
Tanya
Telerik team
answered on 25 Apr 2018, 08:06 PM
Hi Bart,

Thank you for sharing the sample code.

There are two steps that need to be performed in order to achieve the desired result.

The first one is to ensure that the style that is going to be used is registered in the document's style repository using the AddBuiltInStyle() method:

string heading1StyleId = BuiltInStyleNames.GetHeadingStyleIdByIndex(1);
document.StyleRepository.AddBuiltInStyle(heading1StyleId);

By doing this, the heading style will be applied to the paragraphs as expected.

The second thing is related to the rendering of MS Word - it combines the last paragraph symbol in the section with the section break. This seems to cause an issue when trying to collapse the content. To overcome that, you can add an additional paragraph at the end of the current section:

section.Blocks.AddParagraph().Inlines.AddRun(t.Content);
section.Blocks.AddParagraph();

Hope this is helpful.

Regards,
Tanya
Progress Telerik

Tags
WordsProcessing
Asked by
Bart
Top achievements
Rank 1
Answers by
Bart
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or