PrinterSelection.xaml.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using InABox.Wpf;
  2. using System.Collections.Generic;
  3. using System.Drawing.Printing;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. namespace InABox.WPF
  7. {
  8. /// <summary>
  9. /// Interaction logic for PrinterSelection.xaml
  10. /// </summary>
  11. public partial class PrinterSelection : ThemableWindow
  12. {
  13. private readonly List<string> printers = new() { "" };
  14. public PrinterSelection(string value)
  15. {
  16. InitializeComponent();
  17. foreach (string printer in PrinterSettings.InstalledPrinters)
  18. printers.Add(printer);
  19. Combo.ItemsSource = printers;
  20. Value = Combo.Items.Contains(value) ? value : "";
  21. }
  22. public string Value
  23. {
  24. get => Combo.SelectedItem.ToString();
  25. set => Combo.SelectedItem = value;
  26. }
  27. private void OK_Click(object sender, RoutedEventArgs e)
  28. {
  29. DialogResult = true;
  30. Close();
  31. }
  32. private void Cancel_Click(object sender, RoutedEventArgs e)
  33. {
  34. DialogResult = false;
  35. Close();
  36. }
  37. public static bool Execute(ref string value)
  38. {
  39. var edit = new PrinterSelection(value);
  40. if (edit.ShowDialog() == true)
  41. {
  42. value = edit.Value;
  43. return true;
  44. }
  45. return false;
  46. }
  47. private void Combo_SelectionChanged(object sender, SelectionChangedEventArgs e)
  48. {
  49. OK.IsEnabled = !string.IsNullOrWhiteSpace(Combo.SelectedValue.ToString());
  50. }
  51. }
  52. }