簡體   English   中英

C#/ WPF:打印ListView

[英]C#/WPF: Print a ListView

有沒有人知道如何打印(A4)ListView的內容(例如,所有ColumnHeaders,適合頁面寬度和沒有滾動條)? 我在stackoverflow上找到了幾個關於這個的老線程,但沒有完整的答案。

謝謝。

干杯

如果上帝禁止你在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM