using Prism.Commands; using Prism.Services.Dialogs; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace InSituLaboratory.ViewModels.Pages.Dialogs { public class DialogViewModelBase : IDialogAware, INotifyDataErrorInfo { #region IDialogAware接口实现 public string Title { get; set; } public event Action RequestClose; public bool CanCloseDialog() => true; public void OnDialogClosed() { } public virtual void OnDialogOpened(IDialogParameters parameters) { } #endregion #region INotifyDataErrorInfo接口实现 public event EventHandler? ErrorsChanged; public bool HasErrors => ErrorList.Count > 0; public IEnumerable GetErrors(string? propertyName) { if (ErrorList.ContainsKey(propertyName)) return ErrorList[propertyName]; return null; } public Dictionary> ErrorList = new Dictionary>(); public void RaiseErrorsChanged([CallerMemberName] string propNmae = "") { ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propNmae)); } #endregion public DelegateCommand SaveCommand { get; set; } public DialogViewModelBase() { SaveCommand = new DelegateCommand(DoSave); } /// /// 正常关闭弹窗逻辑 /// public virtual void DoSave() { this.RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); } } }