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 打印示例

适用于

另请参阅