Printing in Silverlight: Printing Charts and Auto Scaling
Warning: count(): Parameter must be an array or an object that implements Countable in /nfs/c03/h04/mnt/50561/domains/gergelyorosz.com/html/wp-content/plugins/wp-syntax/wp-syntax.php on line 76
Printing support has been introduced in Silverlight 4. This means that any part of the visual tree can be printed with some simple API calls (see the Printing Basics section on my Advanced Printing in Silverlight post). This post provides an example to print charts and looks at how elements can be auto scaled to fit the page size.
Printing a chart
There are lots of examples on blogs demonstrating printing on simple elements. However I wanted to test how the printing functionality performs when working with charts.
I chose to use the most widespread (and free) charting component, the Silverlight Toolkit. In my example I’ve created four charts and added printing support to all of them like this:
Chart chartToPrint; // The element to be printed PrintDocument doc = new PrintDocument(); // Create the PrintDocument object that will do the printing doc.PrintPage += (s, args) => { // Set the chart that needs to be printed. // As soon as this is set, printing starts args.PageVisual = chartToPrint; }
In the example the whole page can be printed as well by clicking on the Print whole page button. In this case the LayoutRoot element is passed as the PageVisual. Test the example yourself:
Read More…