NumberEdit.xaml.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using InABox.Wpf;
  2. using System.Windows;
  3. namespace InABox.WPF
  4. {
  5. /// <summary>
  6. /// Interaction logic for NumberEdit.xaml
  7. /// </summary>
  8. public partial class NumberEdit : ThemableWindow
  9. {
  10. public NumberEdit(string title, int min, int max, int value)
  11. {
  12. InitializeComponent();
  13. Title = title;
  14. Value = value;
  15. Editor.Minimum = min;
  16. Editor.Maximum = max;
  17. }
  18. public int Value
  19. {
  20. get => Editor.Value.HasValue ? Editor.Value.Value : 0;
  21. set => Editor.Value = value;
  22. }
  23. private void OK_Click(object sender, RoutedEventArgs e)
  24. {
  25. DialogResult = true;
  26. Close();
  27. }
  28. private void Cancel_Click(object sender, RoutedEventArgs e)
  29. {
  30. DialogResult = false;
  31. Close();
  32. }
  33. public static bool Execute(string title, int min, int max, ref int value)
  34. {
  35. var edit = new NumberEdit(title, min, max, value);
  36. if (edit.ShowDialog() == true)
  37. {
  38. value = edit.Value;
  39. return true;
  40. }
  41. return false;
  42. }
  43. }
  44. }