DateEdit.xaml.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using InABox.Wpf;
  2. using System.Windows;
  3. using System.Windows.Controls.Primitives;
  4. namespace InABox.WPF
  5. {
  6. /// <summary>
  7. /// Interaction logic for DateEdit.xaml
  8. /// </summary>
  9. public partial class DateEdit : ThemableWindow
  10. {
  11. public DateEdit(string title, DateTime value)
  12. {
  13. InitializeComponent();
  14. Title = title;
  15. Value = value;
  16. }
  17. public DateTime Value
  18. {
  19. get => Calendar.SelectedDate ?? DateTime.MinValue;
  20. set => Calendar.SelectedDate = 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 DateTime value)
  33. {
  34. var edit = new DateEdit(title, value);
  35. if (edit.ShowDialog() == true)
  36. {
  37. value = edit.Value;
  38. return true;
  39. }
  40. return false;
  41. }
  42. private void Calendar_GotMouseCapture(object sender, System.Windows.Input.MouseEventArgs e)
  43. {
  44. var originalElement = e.OriginalSource as UIElement;
  45. if(originalElement is CalendarDayButton || originalElement is CalendarItem)
  46. {
  47. originalElement.ReleaseMouseCapture();
  48. }
  49. }
  50. }
  51. }