I have created a flow document. In case the document is printed or saved to a file I would like to add a TOC to the start of the document.
What is the correct way of creating a TOC in a flowdocument? Can it be created automatically or should I add the TOC as the last thing looping through all the Paragraphs/Sections and manually add them to a table? If the manual creation is the way to go the next question that appears is how to determine the page number a Paragraph/Section is located on?
I did not find a way to do this automatically. But the following works:
DynamicDocumentPaginator
Note: If the TOC will span multiple pages more than one iteration is needed.