AddLightControllerViewModel.cs 2.0 KB

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