DateSelectorViewModel.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using CommunityToolkit.Mvvm.Input;
  3. using DialogHostAvalonia;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace InABox.Avalonia.Components.DateSelector;
  10. public partial class DateSelectorViewModel : ObservableObject, IPopupViewModel<DateTime?>, IViewModelBase
  11. {
  12. [ObservableProperty]
  13. private DateTime? _date;
  14. public bool IsClosed { get; private set; }
  15. public bool BackButtonVisible { get; set; }
  16. public bool ProgressVisible { get; set; }
  17. public AvaloniaMenuItemCollection PrimaryMenu { get; set; } = new();
  18. public AvaloniaMenuItemCollection SecondaryMenu { get; set; } = new();
  19. private DateTime? _result;
  20. public DateTime? GetResult()
  21. {
  22. return _result;
  23. }
  24. public void Close(DateTime? result)
  25. {
  26. _result = result;
  27. IsClosed = true;
  28. DialogHost.GetDialogSession(null)?.Close();
  29. }
  30. public Task Activate()
  31. {
  32. return Task.CompletedTask;
  33. }
  34. public Task Deactivate()
  35. {
  36. return Task.CompletedTask;
  37. }
  38. [RelayCommand]
  39. private void Cancel()
  40. {
  41. Close(null);
  42. }
  43. [RelayCommand]
  44. private void Clear()
  45. {
  46. Close(DateTime.MinValue);
  47. }
  48. [RelayCommand]
  49. private void Today()
  50. {
  51. Close(DateTime.Today);
  52. }
  53. [RelayCommand]
  54. private void Select()
  55. {
  56. Close(Date);
  57. }
  58. }