TimeSelectorViewModel.cs 706 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using CommunityToolkit.Mvvm.Input;
  3. namespace InABox.Avalonia.Components.TimeSelector;
  4. public partial class TimeSelectorViewModel : BasePopupViewModel<TimeSpan?>
  5. {
  6. [ObservableProperty]
  7. private TimeSpan? _time;
  8. [ObservableProperty]
  9. private Func<TimeSpan?>? _getTime;
  10. [RelayCommand]
  11. private void Cancel()
  12. {
  13. Close(null);
  14. }
  15. [RelayCommand]
  16. private void Clear()
  17. {
  18. Close(TimeSpan.MinValue);
  19. }
  20. [RelayCommand]
  21. private void Now()
  22. {
  23. Close(DateTime.Now.TimeOfDay);
  24. }
  25. [RelayCommand]
  26. private void Select()
  27. {
  28. Close(GetTime is null ? Time : GetTime());
  29. }
  30. }