有没有人知道如何打印(A4)ListView的内容(例如,所有的ColumnHeaders,适合页面宽度而没有滚动条)?我在stackoverflow上找到了几个关于这个的老线程,但没有完整的答案。
谢谢。
干杯
答案 0 :(得分:1)
有人问过msdn,看起来你需要create a Fixed Document, loop over the ListView datasouce and build the table cells and rows in the created document.
答案 1 :(得分:0)
答案 2 :(得分:0)
如果上帝禁止,您需要在2019年这样做:
private void Button_Click(object sender, RoutedEventArgs e)
{
FlowDocument fd = new FlowDocument();
//TaskViewModel.Tasks is the collection (List<> in my case) your ListView takes data from
foreach (var item in TaskViewModel.Tasks) {
fd.Blocks.Add(new Paragraph(new Run(item.ToString()))); //you may need to create a ToString method in your type, if it's string it's ok
}
PrintDialog pd = new PrintDialog();
if (pd.ShowDialog() != true) return;
fd.PageHeight = pd.PrintableAreaHeight;
fd.PageWidth = pd.PrintableAreaWidth;
IDocumentPaginatorSource idocument = fd as IDocumentPaginatorSource;
pd.PrintDocument(idocument.DocumentPaginator, "Printing Flow Document...");
}
部分代码的信用: http://miteshsureja.blogspot.com/2012/06/printing-flow-document-using-wpf.html