[英]C#/WPF: Print a ListView
有沒有人知道如何打印(A4)ListView的內容(例如,所有ColumnHeaders,適合頁面寬度和沒有滾動條)? 我在stackoverflow上找到了幾個關於這個的老線程,但沒有完整的答案。
謝謝。
干杯
有人在msdn上詢問,看起來你需要創建一個固定文檔,遍歷ListView數據並在創建的文檔中構建表格單元格和行。
如果上帝禁止你在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.