/// <summary>
        /// Event handler for clicks on the "Enumerate printers" button. Enumerates printers
        /// and updates the data binding on the ComboBox.
        /// </summary>
        private async void EnumeratePrinters_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                rootPage.NotifyUser("Enumerating printers. Please wait", NotifyType.StatusMessage);

                // Retrieve the running app's package family name, and enumerate associated printers.
                string currentPackageFamilyName = Windows.ApplicationModel.Package.Current.Id.FamilyName;

                // Enumerate associated printers.
                PrinterEnumeration pe = new PrinterEnumeration(currentPackageFamilyName);
                List<PrinterInfo> associatedPrinters = await pe.EnumeratePrintersAsync();

                // Update the data binding source on the combo box that displays the list of printers.
                PrinterComboBox.ItemsSource = associatedPrinters;
                if (associatedPrinters.Count > 0)
                {
                    PrinterComboBox.SelectedIndex = 0;
                    rootPage.NotifyUser(associatedPrinters.Count + " printers enumerated", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser(DisplayStrings.NoPrintersEnumerated, NotifyType.ErrorMessage);
                }
            }
            catch (Exception exception)
            {
                rootPage.NotifyUser("Caught an exception: " + exception.Message, NotifyType.ErrorMessage);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Event handler for clicks on the "Enumerate printers" button. Enumerates printers
        /// and updates the data binding on the ComboBox.
        /// </summary>
        private async void EnumeratePrinters_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                rootPage.NotifyUser("Enumerating printers. Please wait", NotifyType.StatusMessage);

                // Retrieve the running app's package family name, and enumerate associated printers.
                string currentPackageFamilyName = Windows.ApplicationModel.Package.Current.Id.FamilyName;

                // Enumerate associated printers.
                PrinterEnumeration pe = new PrinterEnumeration(currentPackageFamilyName);
                List <PrinterInfo> associatedPrinters = await pe.EnumeratePrintersAsync();

                // Update the data binding source on the combo box that displays the list of printers.
                PrinterComboBox.ItemsSource = associatedPrinters;
                if (associatedPrinters.Count > 0)
                {
                    PrinterComboBox.SelectedIndex = 0;
                    rootPage.NotifyUser(associatedPrinters.Count + " printers enumerated", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser(DisplayStrings.NoPrintersEnumerated, NotifyType.ErrorMessage);
                }
            }
            catch (Exception exception)
            {
                rootPage.NotifyUser("Caught an exception: " + exception.Message, NotifyType.ErrorMessage);
            }
        }