Ejemplo n.º 1
0
        /// <summary>
        /// This is the event handler for PrintManager.PrintTaskRequested.
        /// </summary>
        /// <param name="sender">PrintManager</param>
        /// <param name="e">PrintTaskRequestedEventArgs</param>
        private void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e)
        {
            PrintTask printTask = null;

            printTask = e.Request.CreatePrintTask(_printTaskName, sourceRequested =>
            {
                ApplyPrintSettings(printTask);

                // 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.
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        foreach (var element in _stateBags.Keys)
                        {
                            _stateBags[element].Restore(element);
                        }
                        _stateBags.Clear();

                        DetachCanvas();
                        _canvasContainer.RequestedTheme = ElementTheme.Default;

                        switch (args.Completion)
                        {
                        case PrintTaskCompletion.Failed:
                            {
                                OnPrintFailed?.Invoke();
                                break;
                            }

                        case PrintTaskCompletion.Canceled:
                            {
                                OnPrintCanceled?.Invoke();
                                break;
                            }

                        case PrintTaskCompletion.Submitted:
                            {
                                OnPrintSucceeded?.Invoke();
                                break;
                            }
                        }
                    });
                };

                sourceRequested.SetSource(_printDocumentSource);
            });
        }
        /// <summary>
        /// This is the event handler for PrintManager.PrintTaskRequested.
        /// </summary>
        /// <param name="sender">PrintManager</param>
        /// <param name="e">PrintTaskRequestedEventArgs </param>
        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.
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                    {
                        _canvasContainer.RequestedTheme = ElementTheme.Default;
                        await DetachCanvas();

                        switch (args.Completion)
                        {
                        case PrintTaskCompletion.Failed:
                            {
                                OnPrintFailed?.Invoke();
                                break;
                            }

                        case PrintTaskCompletion.Canceled:
                            {
                                OnPrintCanceled?.Invoke();
                                break;
                            }

                        case PrintTaskCompletion.Submitted:
                            {
                                OnPrintSucceeded?.Invoke();
                                break;
                            }
                        }
                    });
                };

                sourceRequested.SetSource(_printDocumentSource);
            });
        }