Bitmap > Working with Bitmap for Silverlight > Printing the Image |
Once the image is loaded we can easily print. Silverlight 4's printing capabilities add plenty of value to almost any Silverlight application. The printing features basically include a PrintDocument component. We will be modeling our printing code after the same sample from Microsoft used for drag-and-drop. To print we simply call the PrintDocument.Print method, and in the PrintPage event we set the document's PageVisual property to any UI Element we want, in this case it's our image container. We could, if we wanted, print the entire toolbar with the image too but that's just odd.
C# |
Copy Code
|
---|---|
PrintDocument printDocument = new PrintDocument(); private void btnPrint_Click(object sender, RoutedEventArgs e) { printDocument.Print("My Image"); } void printDocument_PrintPage(object sender, PrintPageEventArgs e) { e.PageVisual = imageGrid; e.HasMorePages = false; } |