using InABox.Wpf;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Windows;
using System.Windows.Controls;
namespace InABox.WPF
{
///
/// Interaction logic for PrinterSelection.xaml
///
public partial class PrinterSelection : ThemableWindow
{
private readonly List 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());
}
}
}