TimeEdit.xaml.cs 1.1 KB

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