Monday, July 18, 2011

printing in silverlight 4

Printing is one of the features that was not present in Silverlight 3 and previous versions.

All you have to do is add a reference to:

System.Windows.Printing

Then, add the following code in the .cs file:

void PrintButton_Click(object sender, RoutedEventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += (a, b) =>
{
b.PageVisual = this.grdReport;
};
pd.Print("Print");
}

Make sure that you have a x:Name="grdReport" in your xaml to make it available for printing during runtime. This code will open the Print Dialog box and will show the printers in your network, then just click Print button.

That's all folks! Programming is in your veins, don't stop til your blood is flowing...

No comments: