TimeEdit.xaml.cs 1.2 KB

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