ConfirmationPopupViewModel.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Prism.Commands;
  7. using Prism.Interactivity.InteractionRequest;
  8. using Prism.Mvvm;
  9. using Prism.Services.Dialogs;
  10. namespace OHV.Module.Interactivity
  11. {
  12. public class ConfirmationPopupViewModel : BindableBase, IDialogAware
  13. {
  14. private DelegateCommand<string> _closeDialogCommand;
  15. public DelegateCommand<string> CloseDialogCommand =>
  16. _closeDialogCommand ?? (_closeDialogCommand = new DelegateCommand<string>(CloseDialog));
  17. private string _message;
  18. public string Message
  19. {
  20. get { return _message; }
  21. set { SetProperty(ref _message, value); }
  22. }
  23. private string _title = "Notification";
  24. public string Title
  25. {
  26. get { return _title; }
  27. set { SetProperty(ref _title, value); }
  28. }
  29. public event Action<IDialogResult> RequestClose;
  30. public ConfirmationPopupViewModel()
  31. {
  32. }
  33. protected virtual void CloseDialog(string parameter)
  34. {
  35. ButtonResult result = ButtonResult.None;
  36. if (parameter?.ToLower() == "true")
  37. result = ButtonResult.OK;
  38. else if (parameter?.ToLower() == "false")
  39. result = ButtonResult.Cancel;
  40. RaiseRequestClose(new DialogResult(result));
  41. }
  42. public virtual void RaiseRequestClose(IDialogResult dialogResult)
  43. {
  44. RequestClose?.Invoke(dialogResult);
  45. }
  46. public bool CanCloseDialog()
  47. {
  48. return true;
  49. }
  50. public void OnDialogClosed()
  51. {
  52. }
  53. public void OnDialogOpened(IDialogParameters parameters)
  54. {
  55. Message = parameters.GetValue<string>("message");
  56. }
  57. }
  58. }