0
我正在使用WPF FixedDocument和數據綁定來獲取簡單的發票報告。在軟件本身內部查看時,完美工作。以編程方式打印FixedDocument
但我想打印一系列的發票在一次點擊。下面的代碼完美地工作(快速'骯髒,只是直接在viewmodel內部加載一張發票,用於測試目的),當我選擇XPS編寫器時,bu打印到真實打印機時無法正確打印。我無法看到與報告綁定的數據。所有的圖形元素,如線條都在那裏,但沒有數據。 (當我用相同的按鈕打印de xps寫入器打印機時,所有數據都存在,並且正確...)
任何想法?
private void ExecutePrintCommand(object sender, ExecutedRoutedEventArgs args)
{
var invs = args.Parameter as IList<object>;
using (CompuDataContext db = new CompuDataContext())
{
DataLoadOptions dl = new DataLoadOptions();
dl.LoadWith<Invoice>(f => f.Invoicelines);
db.LoadOptions = dl;
ReportViewer viewer = new ReportViewer();
PrintDialog dlg = new PrintDialog();
if (dlg.ShowDialog() == true)
{
PrintQueue q = dlg.PrintQueue;
foreach (var o in invs)
{
InvoiceListDisplay inv = o as InvoiceListDisplay;
Invoice invoice = db.Invoices.Single(f => f.Id == inv.Id);
viewer.DataContext = new InvoicePrintViewModel(invoice);
XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(q);
xpsdw.Write(viewer.Document);
}
}
}
}