WPF: Best method for printing paginated datagrids

六月ゝ 毕业季﹏ 提交于 2019-12-18 05:48:08

问题


Boy did I get an education looking into this. I guess I've been spoiled by Powerbuilder, which has fantastic functionality for this out of the box.

Does anyone seriously write custom documentpaginator objects to handle reporting needs for their LOB apps? I want to be able to print "for free" and not have to code like crazy just to take whats on the screen and throw it on paper.

How are people doing this? Does anyone have a recommended 3rd party for allowing printing of largish datagrids?

Thanks


回答1:


Paginating datagrids is a huge, huge pain. Simply drawing the grid on a page will not work as you have to handle things like fixed layout, expanding cells horizontally and vertically to show all data, word wrapping, splitting columns and rows into the page margin, splitting cells that overflow a page into multiple pages. Remember you can't scroll or resize a control on a piece of paper. Even if you find a magic control that can do all that, a grid with borders, shadows, and backgrounds that look good on a screen won't look good on paper.

For an old WinForms app that printed datagrids we implemented a completely separate report API for printouts. We printed the underlying ADO.Net dataSource using the free ReportViewer control. A tutorial is at gotreportviewer.com.




回答2:


I've found the easiest way is to implement a generalized DocumentPaginator class for paginating anything I can put on screen. With my DocumentPaginator I don't need to worry about printing because I can take any arbitrary WPF control and tell it to print, and it will take multiple pages if necessary to display all the data.

I also use an inherited attached bool property "PrintView" that the user can control. Some of my controls change their appearance somewhat using a trigger on the "PrintView" property, so they will look better when printed.

I describe my DocumentPaginator solution in more detail in this answer, including a description of the algorithm required.



来源:https://stackoverflow.com/questions/3009575/wpf-best-method-for-printing-paginated-datagrids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!