I have found a strange behaviour while trying to print a FlowDocument
which is stored inside the .xaml file. Let me show you how this works. We have a simple ViewModel-like class:
public class FooViewModel
{
public FlowDocument Fd { get; set; }
public FooViewModel()
{
this.Fd = Application.LoadComponent(new Uri("/someassembly;component/somepath.xaml", UriKind.Relative)) as FlowDocument;
}
public void Print()
{
PrintDialog pd new PrintDialog();
pd.PrintQueue = new PrintQueue(new LocalPrintServer(), "Canon MP280 series");
FlowDocument document = this.Fd;
document.DataContext = new LabelTicket(); //stores data for printing
DocumentPaginator dp = ((IDocumentPaginatorSource)document).DocumentPaginator;
pd.PrintDocument(dp, "someTitle");
}
}
This code works, printing job is started and the physical printer is doing it's job. But when we change one line in Print()
method to:
FlowDocument document = Application.LoadComponent(new Uri("/someassembly;component/somepath.xaml", UriKind.Relative)) as FlowDocument;
Something strange starts to happen. Delaying the component loading to actual printing makes printing impossible. The printing job appears in the Windows Printing Queue of this particular printer, but it disappears almost immediately. Turning on the Windows Event Tracking for printing shows that: "Win32 error code returned by the print processor: 63 (0x3f)." Changing the printer to any other physical printer gives the same effect.
On the other hand changing printer to any non-physical printer like "Microsoft XPS Document Writer" performs this printing without problem.
I've also tried loading the FlowDocument
from ResourceDictionary but with the same effect. Could someone give me a hint how to solve this problem?