Export (0) Print
Expand All

PrintDocument.PrintPage Event

Silverlight

Occurs when each page is printing.

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

'Declaration
Public Event PrintPage As EventHandler(Of PrintPageEventArgs)

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()
        InitializeComponent()
        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



<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"/>
  </StackPanel>


Silverlight

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

ADD
Show:
© 2014 Microsoft