繁体   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