Thursday, May 27, 2010

Printing In Silverlight 4.0

In silverlight 4.0 the main API for printing is PrintDocument class which lives in System.Windows.Printing namespace. Here are the steps we need to do  for a Printing.

1) First Create instance of  PrintDocument class.

2) Next Implement the PrintPage event handler and  Set PageVisual to the UIElement you want to print.

3)  Finally call Print() method.

This is very easy way to print this is same as screen printing.

let see in action

First Create Silverlight application project.

image 

In the Next Dialog box we just say click OK .

image

now lets add some XAML code to build UI with some Text and try to print them.

image

Here is my GUI with some sample Contact Lists.

image

 

   Event handler to handle Printpage event.

     Here i am  using Lambda Expression (C# 3.0)  basically the down rectangle code replaced by the above Rectangle  Lambda Expression.

image

image

Nandri(Thanks)

SreenivasaRagavan.

No comments: