Displaying a Multi-Paged FlowDocument with repeati

2019-08-10 04:34发布

问题:

I am trying to add Headers / footers to a WPF FlowDocument. I Found a solution on the Internet here that is using a custom Paginator Class to do this. Unfortunately this only works when printing out the Document, which is not what I intend to do. My Idea was to use a FlowDocumentPageReader or something similar with a custom paginator, but somehow I can't figure out how I would do that, maybe anyone can give me a hint in the right Direction.

回答1:

If you are just displaying the FlowDocument and not printing it, you can implement headers and footers by creating a control template for the FlowDocumentPageViewer.

In the template, place textblocks above and below the DocumentPageView, and bind them to the appropriate values.

For example, if you want a page number:

<TextBlock Text="{Binding Path=MasterPageNumber, RelativeSource={RelativeSource TemplatedParent}" FontSize="14" FontWeight="Bold" />

and so on for title, etc.

You can wrap the textblocks and DocumentPageView with a border so the whole thing appears as one page.