PrintManager.PrintTaskRequested Событие

Определение

Возникает при запросе на печать. Это событие может быть вызвано действием пользователя или программным вызовом печати с помощью метода ShowPrintUIAsync .

// 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) 

Тип события

Комментарии

При добавлении возможностей печати в приложение UWP необходимо реализовать обработчик событий для обработки этого события при его возникновении. Ниже приведен фрагмент кода из примера печати UWP , в который показано, как обрабатывать это событие:

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);
    });
}

Полный список для этого и других сценариев печати с помощью PrintTaskRequested см. в разделе Печать и пример печати UWP.

Применяется к

См. также раздел