From 97cf5197cf5b882b2c689d8dc2b555f2edf8f418 Mon Sep 17 00:00:00 2001 From: Dave Wilson Date: Tue, 17 Mar 2015 19:50:07 -0700 Subject: Initial publish --- .../ExtensionSample/ValidationModalDialog.xaml.cs | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/ValidationModalDialog.xaml.cs (limited to 'print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/ValidationModalDialog.xaml.cs') diff --git a/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/ValidationModalDialog.xaml.cs b/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/ValidationModalDialog.xaml.cs new file mode 100644 index 00000000..0728c84c --- /dev/null +++ b/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/ValidationModalDialog.xaml.cs @@ -0,0 +1,108 @@ +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved +// +// +// Abstract: +// +// This file contains as the interaction logic for ValidationModaldialog. +// This dialog prevents the user from making changes to print ticket settings when asynchronous +// validation is being performed. + +using System; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; + +using Microsoft.Samples.Printing.PrinterExtension.Types; + +namespace Microsoft.Samples.Printing.PrinterExtension +{ + /// + /// Interaction logic for ValidationModalDialog.xaml + /// This dialog prevents the user from changing print preferences when validation is in progress. + /// + public partial class ValidationModalDialog : UserControl + { + public ValidationModalDialog() + { + InitializeComponent(); + Visibility = Visibility.Hidden; + } + + /// + /// Starts the asynchronous operation. + /// + /// Async operation context. + public void StartAsyncOperation(IPrintSchemaAsyncOperation asyncOperationToStart) + { + this.asyncOperationContext = asyncOperationToStart; + Visibility = Visibility.Visible; + asyncOperationToStart.Completed += asyncOperation_Completed; + asyncOperationToStart.Start(); + } + + + /// + /// This method is invoked from a different thread once asynchronous validation is completed. + /// + /// + /// + private void asyncOperation_Completed(object sender, PrintSchemaAsyncOperationEventArgs e) + { + ValidationHResult = e.StatusHResult; + HideWindow(); + + if (Completed != null) + { + Completed(this, e); + } + } + + /// + /// Hides the current window. + /// + private void HideWindow() + { + this.Dispatcher.Invoke(new Action(() => + { + Visibility = Visibility.Hidden; + })); + } + + + /// + /// Result of the validation operation. + /// + public int ValidationHResult + { + get; + private set; + } + + /// + /// Invoked then the "Cancel" button is clicked. + /// + /// + /// + private void CancelValidationButton_Click(object sender, RoutedEventArgs e) + { + asyncOperationContext.Cancel(); + HideWindow(); + } + + /// + /// Invoked when the asynchronous operation is completed. + /// + public event EventHandler Completed; + + /// + /// Asynchronous operation context. + /// + private IPrintSchemaAsyncOperation asyncOperationContext; + } +} -- cgit v1.3.1