AddLightControllerViewModel.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using Prism.Services.Dialogs;
  4. using System;
  5. using TeamAAS_VP.Models.Lights;
  6. using TeamAAS_VP.Resources.Languages;
  7. namespace TeamAAS_VP.ViewModels.Setting
  8. {
  9. public class AddLightControllerViewModel : BindableBase, IDialogAware
  10. {
  11. private LightControllerConfig _LightController;
  12. public LightControllerConfig LightController
  13. {
  14. get => _LightController; set => SetProperty(ref _LightController, value);
  15. }
  16. private DelegateCommand _ConfirmCommand;
  17. public DelegateCommand ConfirmCommand => _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand, CanExecuteConfirmCommand).ObservesProperty(() => LightController.Name));
  18. private DelegateCommand _CancelCommand;
  19. public DelegateCommand CancelCommand => _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
  20. public AddLightControllerViewModel()
  21. {
  22. }
  23. public string Title { get; set; } = "Ìí¼Ó¹âÔ´¿ØÖÆÆ÷";
  24. public event Action<IDialogResult> RequestClose;
  25. public bool CanCloseDialog() => true;
  26. public void OnDialogClosed() { }
  27. public void OnDialogOpened(IDialogParameters parameters)
  28. {
  29. LightController = new LightControllerConfig() { Id = 0, Name = "New Controller", LightModel = TeamAAS_VP.Core.Lights.LightModel.KCS_KDC_12V60W_4T };
  30. }
  31. bool CanExecuteConfirmCommand()
  32. {
  33. return LightController != null && !string.IsNullOrEmpty(LightController.Name);
  34. }
  35. void ExecuteConfirmCommand()
  36. {
  37. var p = new DialogParameters();
  38. p.Add("LightController", LightController);
  39. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, p));
  40. }
  41. void ExecuteCancelCommand()
  42. {
  43. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
  44. }
  45. }
  46. }