Search code examples
c#blockflowdocument

Is there a way to retrieve a single block from a flowdocument by index?


I have created a flowdocument and added a number of blocks. I now need to access the blocks based on an index value. I.E. I need the first paragraph, or the second paragraph.

How can I get a specific block given an index?


Solution

  • I finally managed to resolve this issue.

    First, I created a list for the blocks

    List<Block> Pblocks = new List<Block>();
    Pblocks = TailoredResources_Reading_Text.Document.Blocks.ToList();
    

    Then, I assigned the block to a paragraph

    Paragraph paragraph = Pblocks[1] as Paragraph;
    

    Finally, using a run to get the first inline via a list

    Run sText = paragraph.Inlines.ToList()[0] as Run;