Dela via


PrintManager.ShowPrintUIAsync Method

Definition

Programmatically initiates the user interface for printing content.

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)

Returns

A Boolean value to indicate a TRUE for success or a FALSE for a failure.

Attributes

Remarks

This method may be used by an application which has already used GetForCurrentView to retrieve the PrintManager instance and has registered a listener for the PrintTaskRequested event to initiate the printing user experience. ShowPrintUIAsync displays the appropriate printing window. If printing can't be performed at that time, the method will throw an exception. We recommend catching these exceptions and letting the user know when printing can't proceed, as shown here.

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

In this example, a print window is displayed in the event handler for a button click. If the method throws an exception (because printing can't be performed at that time), a ContentDialog control informs the user of the situation. For more info about printing from your app, see Printing.

Applies to

See also