Oliver Hanappi
Oliver Hanappi

Reputation: 12346

How to print WPF Grid paged?

I'm printing a WPF grid. As long as the data fits on one page, everything works fine. But sometimes the grid contains more data. Therefore I need to split the grid into multiple pages. Can anybody help me?

My code looks like this (visual is the grid).

var printCapabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);

var size = new Size(printCapabilities.PageImageableArea.ExtentWidth,
     printCapabilities.PageImageableArea.ExtentHeight);

visual.Measure(size);
visual.Arrange(new Rect(new Point(printCapabilities.PageImageableArea.OriginWidth,
    printCapabilities.PageImageableArea.OriginHeight), size));

printDialog.PrintVisual(visual, "Print ListView");

Should I try another control? I've tried WPF Toolkit DataGrid, but I couldn't manage to get it printed. I've heard something of a flow document, can this help me?

Upvotes: 2

Views: 4215

Answers (1)

bearda
bearda

Reputation: 311

It sounds like you want to use PrintDocument instead of PrintVisual. You will probably need to implement your own DocumentPaginator class to split your grid into separate printable documents, though.

Upvotes: 1

Related Questions