共用方式為


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 列印範例

適用於

另請參閱