Esempio n. 1
0
        /// <summary>
        /// This method is invoked when a printer is selected on the UI.
        /// Displays the print jobs in the selected printer's queue.
        /// </summary>
        private void Printer_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                // Remove the current printer queue view (if any) before displaying the new view.
                if (currentPrinterQueueView != null)
                {
                    currentPrinterQueueView.OnChanged -= OnPrinterQueueViewChanged;
                    currentPrinterQueueView            = null;
                }

                // Retrieve a COM IPrinterExtensionContext object, using the static WinRT factory.
                // Then instantiate one "PrinterExtensionContext" object that allows operations on the COM object.
                PrinterInfo             queue      = (PrinterInfo)PrinterComboBox.SelectedItem;
                Object                  comComtext = Windows.Devices.Printers.Extensions.PrintExtensionContext.FromDeviceId(queue.DeviceId);
                PrinterExtensionContext context    = new PrinterExtensionContext(comComtext);

                // Display the printer queue view.
                const int FirstPrintJobEnumerated = 0;
                const int LastPrintJobEnumerated  = 10;

                currentPrinterQueueView            = context.Queue.GetPrinterQueueView(FirstPrintJobEnumerated, LastPrintJobEnumerated);
                currentPrinterQueueView.OnChanged += OnPrinterQueueViewChanged;
            }
            catch (Exception exception)
            {
                rootPage.NotifyUser("Caught an exception: " + exception.Message, NotifyType.ErrorMessage);
            }
        }
        /// <summary>
        /// Event handler for clicks on the "Send bidi request" button.
        /// </summary>
        private void SendBidiRequest_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PrinterInfo queue = (PrinterInfo)PrinterComboBox.SelectedItem;

                // Retrieve a COM IPrinterExtensionContext object, using the static WinRT factory.
                // Then instantiate one "PrinterExtensionContext" object that allows operations on the COM object.
                Object comComtext = Windows.Devices.Printers.Extensions.PrintExtensionContext.FromDeviceId(queue.DeviceId);
                PrinterExtensionContext context = new PrinterExtensionContext(comComtext);

                // Create an instance of the callback object, and perform an asynchronous 'bidi set' operation.
                PrinterBidiSetRequestCallback callback = new PrinterBidiSetRequestCallback();

                // Add an event handler to the callback object's OnBidiResponseReceived event.
                // The event handler will be invoked once the Bidi response is received.
                callback.OnBidiResponseReceived += OnBidiResponseReceived;

                // Send the Bidi "Set" query asynchronously.
                IPrinterExtensionAsyncOperation operationContext
                    = context.Queue.SendBidiSetRequestAsync(BidiQueryInput.Text, callback);

                // Note: The 'operationContext' object can be used to cancel the operation if required.
            }
            catch (Exception exception)
            {
                rootPage.NotifyUser("Caught an exception: " + exception.Message, NotifyType.ErrorMessage);
            }
        }