Jaa


PrintManager.PrintTaskRequested Event

Definition

Raised when a request to print has occurred. This event may be triggered by user action or via programmatic invocation of printing via the ShowPrintUIAsync method.

// Register
event_token PrintTaskRequested(TypedEventHandler<PrintManager, PrintTaskRequestedEventArgs const&> const& handler) const;

// Revoke with event_token
void PrintTaskRequested(event_token const* cookie) const;

// Revoke with event_revoker
PrintManager::PrintTaskRequested_revoker PrintTaskRequested(auto_revoke_t, TypedEventHandler<PrintManager, PrintTaskRequestedEventArgs const&> const& handler) const;
public event TypedEventHandler<PrintManager,PrintTaskRequestedEventArgs> PrintTaskRequested;
function onPrintTaskRequested(eventArgs) { /* Your code */ }
printManager.addEventListener("printtaskrequested", onPrintTaskRequested);
printManager.removeEventListener("printtaskrequested", onPrintTaskRequested);
- or -
printManager.onprinttaskrequested = onPrintTaskRequested;
Public Custom Event PrintTaskRequested As TypedEventHandler(Of PrintManager, PrintTaskRequestedEventArgs) 

Event Type

Remarks

When you add print capabilities to your UWP app, you have to implement an event handler to process this event when it is raised. Here is a code snippet from the UWP print sample that shows how to handle this event:

protected virtual void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e)
{
    PrintTask printTask = null;
    printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", sourceRequested =>
    {
        // Print Task event handler is invoked when the print job is completed.
        printTask.Completed += async (s, args) =>
        {
            // Notify the user when the print operation fails.
            if (args.Completion == PrintTaskCompletion.Failed)
            {
                await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    MainPage.Current.NotifyUser("Failed to print.", NotifyType.ErrorMessage);
                });
            }
        };

        sourceRequested.SetSource(printDocumentSource);
    });
}

To see the complete listing for this and other printing scenarios using PrintTaskRequested, see Printing and the UWP print sample.

Applies to

See also