using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; namespace OHV.Module.Interactivity { public class NotificationViewModel : BindableBase, IDialogAware { private Visibility errorVisibillity; public Visibility ErrorVisibillity { get { return errorVisibillity; } set { if (SetProperty(ref this.errorVisibillity, value)){ } } } private Visibility okVisibillity; public Visibility OKVisibillity { get { return okVisibillity; } set { if (SetProperty(ref this.okVisibillity, value)) { } } } private DelegateCommand _closeDialogCommand; public DelegateCommand CloseDialogCommand => _closeDialogCommand ?? (_closeDialogCommand = new DelegateCommand(CloseDialog)); private string _message; public string Message { get { return _message; } set { SetProperty(ref _message, value); } } private string _title = "Notification"; public string Title { get { return _title; } set { SetProperty(ref _title, value); } } public event Action RequestClose; public NotificationViewModel() { } protected virtual void CloseDialog(string parameter) { ButtonResult result = ButtonResult.None; if (parameter?.ToLower() == "true") result = ButtonResult.OK; else if (parameter?.ToLower() == "false") result = ButtonResult.Cancel; RaiseRequestClose(new DialogResult(result)); } public virtual void RaiseRequestClose(IDialogResult dialogResult) { RequestClose?.Invoke(dialogResult); } public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { Message = parameters.GetValue("message"); var isOK = parameters.GetValue("Type"); if (isOK) { this.ErrorVisibillity = Visibility.Hidden; this.OKVisibillity = Visibility.Visible; } else { this.ErrorVisibillity = Visibility.Visible; this.OKVisibillity = Visibility.Hidden; } } } }