using CapMachine.Wpf.Services; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using Prism.Ioc; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CapMachine.Wpf.ViewModels { public abstract class HostDialogViewModel : BindableBase, IHostDialogAware { public string Title { get; set; } public string IdentifierName { get; set; } public DelegateCommand SaveCommand { get; private set; } public DelegateCommand CancelCommand { get; private set; } private IHostDialogService dialogService; public HostDialogViewModel() { SaveCommand = new DelegateCommand(async () => await Save()); CancelCommand = new DelegateCommand(Cancel); dialogService = ContainerLocator.Container.Resolve(); } public virtual void Cancel() { dialogService.Close(IdentifierName, new DialogResult(ButtonResult.No)); } public virtual async Task Save() { dialogService.Close(IdentifierName, new DialogResult(ButtonResult.OK)); await Task.CompletedTask; } protected virtual void Save(object value) { DialogParameters param = new DialogParameters(); param.Add("Value", value); dialogService.Close(IdentifierName, new DialogResult(ButtonResult.OK, param)); } protected virtual void Save(DialogParameters param) { dialogService.Close(IdentifierName, new DialogResult(ButtonResult.OK, param)); } public abstract void OnDialogOpened(IDialogParameters parameters); } }