PrintDocument.PrintPage Event

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when each page is printing.

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


Public Event PrintPage As EventHandler(Of PrintPageEventArgs)
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.

Partial Public Class MainPage
    Inherits UserControl
    Private pd As PrintDocument()

    Public Sub New()
        pd = New PrintDocument()

    End Sub

    Private Sub PrintButton_Click(ByVal sender As Object, _
            ByVal e As RoutedEventArgs)
        pd.Print("M yMap")
    End Sub

    Private Sub pd_PrintPage(ByVal sender As Object, _
            ByVal e As PrintPageEventArgs) Handles pd.PrintPage
        e.PageVisual = mapImage
    End Sub
End Class
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"/>

Version Information


Supported in: 5, 4


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