views:

50

answers:

0

Hi Everyone,

We're currently using WPF to create a multi-page invoice document, to then be printed / exported via XPS.

The route we've taken to achieve this is to create a UserControl containing a standard ListBox etc displaying the Invoice lines, this is then included in a FlowDocument inside BlockUIContainer tags.

When this FlowDocument is placed inside FlowDocumentScrollViewer tags in a window, it works perfectly, with the databound content of the UserControl displaying properly. However, when we try to create the same FlowDocument in code, it fails with a "'Cannot create unknown type '{clr-namespace:FOO}FooUserControl" XamlParseException. The FlowDocument can be successfully created programmatically if the UserControl is removed.

This is the FlowDocument XAML:

<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:local="clr-namespace:MARS"
          ColumnWidth="400" FontSize="14" FontFamily="Georgia">
<Paragraph>
    Blah
</Paragraph>

<BlockUIContainer>
    <local:printTestUserControl></local:printTestUserControl>
</BlockUIContainer>

And this is the code we are using to create it in code:

FileStream xamlFile = new FileStream("printTestFlowDoc.xaml", FileMode.Open, FileAccess.Read);            
FlowDocument content = (FlowDocument)XamlReader.Load(xamlFile);
flowDocScrollViewer.Document = content;
xamlFile.Close();

The reason we're creating the FlowDocument in code is to then use a Paginator object to slice it into a series of FixedDocuments to then print / export to XPS, none of which we've yet tried, but from what i've read so far it seems like this is a feasible method of achieving multi-page document printing in WPF (Where the document will have a header on the first page, a totals footer on the last, and x pages of rows in between).

Any advice on this issue, or other methods of doing this would be very welcome.

These are some links we've picked up bits of information from so far, sadly not enough though! (I'll include the other links in comments, as StackOverflow doesn't trust me with more than one link at present!)

See the section "Dynamically Creating a FlowDocument, Data Binding and Printing It" Scott Hanselmann seemed to have the same problem as we did, but adding the line

Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.SystemIdle, new DispatcherOperationCallback(delegate { return null; }), null);

didn't get our FlowDocument to load, however he was only binding to TextBlocks in his FlowDocument, rather than including a UserControl.

Thanks very much for reading this far! and for any help anyone can offer.