| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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<IDialogResult> 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));
- }
- }
- }
|