I'm trying to print a FlowDocument
which consists of an ItemsControl
. I would like to split it up automatically on multiple pages if necessary. Currently I'm unsure why it does output a blank page. I've tried to look up similar questions, though they had not much information I could make use of.
My FlowDocument
looks like this:
<FlowDocument x:Class="PrintFlowDocument.Views.GoWithTheFlow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PrintFlowDocument.Views">
<Paragraph>
<ItemsControl ItemsSource="{Binding StringList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" TextWrapping="Wrap"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Paragraph>
</FlowDocument>
The DataContext
of the FlowDocument
is set upon instantiation and the StringList
property is (currently) initialized in the constructor of the VM.
GoWithTheFlow1 flow = new GoWithTheFlow1() { DataContext = new FlowVM() };
flow.PageHeight = 1122.5196850393702;
flow.PageWidth = 793.70078740157476;
//---
ObservableCollection<string> _StringList;
public ObservableCollection<string> StringList
{
get { return _StringList; }
set { if (_StringList != value) { _StringList = value; NotifyPropertyChanged(() => StringList); } }
}
To print the document, I'm using a XpsDocumentWriter
and print it for test purposes to the XPS printer.
var writer = PrintQueue.CreateXpsDocumentWriter(XPSPrinter);
writer.Write(doc); //IDocumentPaginatorSource...
Is there something I'm doing wrong ? Why does it not display the ItemsControl + content ?
Apparently, there is no support for data-binding in FlowDocument
.
I'm discarding this solution/try and use an existing solution (DocumentPaginator
) for now.