AddLightControllerViewModel.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. //LightController.Init();
  39. p.Add("LightController", LightController.Init());
  40. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, p));
  41. }
  42. void ExecuteCancelCommand()
  43. {
  44. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
  45. }
  46. }
  47. }