Share via


PrintManager.ShowPrintUIAsync 方法

定義

以程式設計方式起始用於列印內容的使用者介面。

public:
 static IAsyncOperation<bool> ^ ShowPrintUIAsync();
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncOperation<bool> ShowPrintUIAsync();
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncOperation<bool> ShowPrintUIAsync();
function showPrintUIAsync()
Public Shared Function ShowPrintUIAsync () As IAsyncOperation(Of Boolean)

傳回

布林值,表示成功為 TRUE,或表示失敗的 FALSE。

屬性

備註

這個方法可由已經使用 GetForCurrentView 的應用程式用來擷取 PrintManager 實例,並已註冊 PrintTaskRequested 事件的接聽程式來起始列印使用者體驗。 ShowPrintUIAsync 會顯示適當的列印視窗。 如果此時無法執行列印,方法會擲回例外狀況。 建議您攔截這些例外狀況,並讓使用者知道列印何時無法繼續,如下所示。

async private void printButton_Click(object sender, RoutedEventArgs e)
{
    try
    {
        // Show print UI
        await Windows.Graphics.Printing.PrintManager.ShowPrintUIAsync();

    }
    catch
    {
        // Printing cannot proceed at this time
        ContentDialog noPrintingDialog = new ContentDialog()
        {
            Title = "Printing error",
            Content = "\nSorry, printing can't proceed at this time.", PrimaryButtonText = "OK"
        };
        await noPrintingDialog.ShowAsync();
    }
}

在這個範例中,事件處理常式中會針對按鈕點擊顯示列印視窗。 如果這個方法擲回例外狀況 (因為當時無法執行列印),ContentDialog 控制項會通知使用者該情況。 如需從您的應用程式列印的詳細資訊,請參閱 列印

適用於

另請參閱