C # / WPF: printing a ListView list

Does anyone have an idea how to print (A4) the contents of a ListView (e.g. with all columns suitable for page width and without scrollbar)? I found some old threads about this in stackoverflow, but didn't get a complete answer.

Thanks.

Greetings

+4
source share
3 answers

If God forbid you need to do it in 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 string it 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..."); } 

Credit for part of the code: http://miteshsureja.blogspot.com/2012/06/printing-flow-document-using-wpf.html

0
source

All Articles