12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using InABox.Wpf;
- using System.Windows;
- using System.Windows.Controls;
- namespace InABox.WPF
- {
- /// <summary>
- /// Interaction logic for PrinterSelection.xaml
- /// </summary>
- public partial class DictionaryEdit : ThemableWindow
- {
- public DictionaryEdit(string[] values, ref int index)
- {
- InitializeComponent();
- Combo.Items.Clear();
- Combo.Items.Add("");
- foreach (var val in values)
- Combo.Items.Add(val);
- Index = index;
- }
- public int Index
- {
- get => Combo.SelectedIndex - 1;
- set => Combo.SelectedIndex = value + 1;
- }
- 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<T>(Dictionary<T, string> values, ref T value)
- {
- var index = values.Keys.ToList().IndexOf(value);
- var edit = new DictionaryEdit(values.Values.ToArray(), ref index);
- if (edit.ShowDialog() == true)
- {
- value = edit.Index > -1 ? values.Keys.ToList()[edit.Index] : default;
- return true;
- }
- return false;
- }
- private void Combo_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- OK.IsEnabled = Combo.SelectedIndex > 0;
- }
- }
- }
|