Printing with Prism + MVVM

Topics: Prism v2 - Silverlight 4
Oct 28, 2010 at 1:47 PM

Hi, I using Prism (MVVM) to develops a Silverlight Application.

I have many views display like wizard.And a button Print (in toolbox)

So how can I print all views or only view that I want?

I think I use Event Aggregation to Publish and Subscriber event Print. Anybody have any suggestion.

Thank you.

Oct 28, 2010 at 6:07 PM


There is no guidance on this topic in Prism out-of-the-box. But there is a document of Printing in Silverlight. Based on this documentation section, you will be able print your views using the following code or something similar(pseudo-code):

PrintDocument pd; 
public PrintService()
pd = new PrintDocument();
pd.PrintPage += new EventHandler<PrintPageEventArgs>(pd_PrintPage);

private void PrintButton_Click(object sender, RoutedEventArgs e)

void pd_PrintPage(object sender, PrintPageEventArgs e)
e.HasMorePages = true; //event occurs multiple times until HasMorePages is false (whether there are more pages to print).
e.PageVisual = views[viewIndex]; // you need to find the way of assigning a different page when the handler is called multiple times.
if(IsTheLastPage) //If this is the last page to print
e.HasMorePages = false; //it prevents to continue occurring

For more information you could also take a look at the PrintDocument class documentation section on MSDN.

Hope this helps.

Fernando Antivero