PrintDocument.PrintPage Event

Occurs when each page is printing.

Namespace:  System.Windows.Printing
Assembly:  System.Windows (in System.Windows.dll)

public event EventHandler<PrintPageEventArgs> PrintPage

Handle this event to specify the contents of the printed page. You can print the entire Silverlight control by setting the PrintPageEventArgs.PageVisual property to the layout root of the Silverlight content. Alternatively, you can print a portion of the Silverlight control by setting PrintPageEventArgs.PageVisual to the named UIElement that you want to print.

After the PrintPage event occurs, the specified PrintPageEventArgs.PageVisual will be sent to the printer to be printed. If the content is too large to fit in the PrintableArea, it will be clipped. If the HasMorePages property is true, the PrintPage event occurs again.

For more information about handling events, see Events Overview for Silverlight.

The following code example shows a button event handler that calls the Print method and an event handler for the PrintPage event. In this example, an Image control, which contains a map, is printed.

public partial class MainPage : UserControl
    PrintDocument pd; 

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


    private void PrintButton_Click(object sender, RoutedEventArgs e)
      pd.Print("My Map");

    void pd_PrintPage(object sender, PrintPageEventArgs e)
        e.PageVisual = mapImage;

<StackPanel x:Name="LayoutRoot">
      <Button Margin="5" Width="200" Content="Click to print" x:Name="PrintButton" 
              Click="PrintButton_Click" />
      <Image Width="600"  Height="600" Source="RedmondMap.jpg" x:Name="mapImage"/>


Supported in: 5, 4

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions