NumberEdit.xaml.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. if(Editor.Value >= Editor.Minimum && Editor.Value <= Editor.Maximum)
  26. {
  27. DialogResult = true;
  28. Close();
  29. }
  30. else
  31. {
  32. MessageBox.Show($"Value must be in range [{Editor.Minimum}, {Editor.Maximum}]");
  33. }
  34. }
  35. private void Cancel_Click(object sender, RoutedEventArgs e)
  36. {
  37. DialogResult = false;
  38. Close();
  39. }
  40. public static bool Execute(string title, int min, int max, ref int value)
  41. {
  42. var edit = new NumberEdit(title, min, max, value);
  43. if (edit.ShowDialog() == true)
  44. {
  45. value = edit.Value;
  46. return true;
  47. }
  48. return false;
  49. }
  50. }
  51. }