using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; using TeamAAS_VP.Models.Lights; using TeamAAS_VP.Resources.Languages; namespace TeamAAS_VP.ViewModels.Setting { public class AddLightControllerViewModel : BindableBase, IDialogAware { private LightControllerConfig _LightController; public LightControllerConfig LightController { get => _LightController; set => SetProperty(ref _LightController, value); } private DelegateCommand _ConfirmCommand; public DelegateCommand ConfirmCommand => _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand, CanExecuteConfirmCommand).ObservesProperty(() => LightController.Name)); private DelegateCommand _CancelCommand; public DelegateCommand CancelCommand => _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand)); public AddLightControllerViewModel() { } public string Title { get; set; } = Lang.Ìí¼Ó¹âÔ´¿ØÖÆÆ÷; public event Action RequestClose; public bool CanCloseDialog() => true; public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { LightController = new LightControllerConfig() { Id = 0, Name = "New Controller", LightModel = TeamAAS_VP.Core.Lights.LightModel.KCS_KDC_12V60W_4T }.Init(); } bool CanExecuteConfirmCommand() { return LightController != null && !string.IsNullOrEmpty(LightController.Name); } void ExecuteConfirmCommand() { var p = new DialogParameters(); p.Add("LightController", LightController.Init()); RequestClose?.Invoke(new DialogResult(ButtonResult.OK, p)); } void ExecuteCancelCommand() { RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); } } }