2009-06-25 72 views
1

如何批量打印繁殖flowdocumets? 以下代碼應打印不同的文檔,但打印相同。只有打印到xps打印機時,此示例才能正常工作。創建printbatch以打印繁殖flowdocuments

var printDialog = new PrintDialog(); 
if(printDialog.ShowDialog() == true) {  
    var xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue); 

    foreach(var person in persons) { 
    var doc = Application.LoadComponent(new Uri("Template.xaml", UriKind.Relative)) as FlowDocument; 
     doc.DataContext = persons; 
     var paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator;   
     xpsDocumentWriter.Write(paginator); 
    } 
    } 

回答

1

這些是線程問題。在分配DataContext之後,請確保線程處理其等待隊列:

Dispatcher.CurrentDispatcher.Invoke(
     DispatcherPriority.SystemIdle, new DispatcherOperationCallback(_ => null), null);