DateEdit.xaml.cs 1.5 KB

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