123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using InABox.Wpf;
- using System.Collections.Generic;
- using System.Drawing.Printing;
- using System.Windows;
- using System.Windows.Controls;
- namespace InABox.WPF
- {
- /// <summary>
- /// Interaction logic for PrinterSelection.xaml
- /// </summary>
- public partial class PrinterSelection : ThemableWindow
- {
- private readonly List<string> printers = new() { "" };
- public PrinterSelection(string value)
- {
- InitializeComponent();
- foreach (string printer in PrinterSettings.InstalledPrinters)
- printers.Add(printer);
- Combo.ItemsSource = printers;
- Value = Combo.Items.Contains(value) ? value : "";
- }
- public string Value
- {
- get => Combo.SelectedItem.ToString();
- set => Combo.SelectedItem = value;
- }
- private void OK_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = true;
- Close();
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- Close();
- }
- public static bool Execute(ref string value)
- {
- var edit = new PrinterSelection(value);
- if (edit.ShowDialog() == true)
- {
- value = edit.Value;
- return true;
- }
- return false;
- }
- private void Combo_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- OK.IsEnabled = !string.IsNullOrWhiteSpace(Combo.SelectedValue.ToString());
- }
- }
- }
|