NotificationViewModel.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using Prism.Commands;
  8. using Prism.Mvvm;
  9. using Prism.Services.Dialogs;
  10. namespace OHV.Module.Interactivity
  11. {
  12. public class NotificationViewModel : BindableBase, IDialogAware
  13. {
  14. private Visibility errorVisibillity;
  15. public Visibility ErrorVisibillity
  16. {
  17. get { return errorVisibillity; }
  18. set { if (SetProperty(ref this.errorVisibillity, value)){ } }
  19. }
  20. private Visibility okVisibillity;
  21. public Visibility OKVisibillity
  22. {
  23. get { return okVisibillity; }
  24. set { if (SetProperty(ref this.okVisibillity, value)) { } }
  25. }
  26. private DelegateCommand<string> _closeDialogCommand;
  27. public DelegateCommand<string> CloseDialogCommand =>
  28. _closeDialogCommand ?? (_closeDialogCommand = new DelegateCommand<string>(CloseDialog));
  29. private string _message;
  30. public string Message
  31. {
  32. get { return _message; }
  33. set { SetProperty(ref _message, value); }
  34. }
  35. private string _title = "Notification";
  36. public string Title
  37. {
  38. get { return _title; }
  39. set { SetProperty(ref _title, value); }
  40. }
  41. public event Action<IDialogResult> RequestClose;
  42. public NotificationViewModel()
  43. {
  44. }
  45. protected virtual void CloseDialog(string parameter)
  46. {
  47. ButtonResult result = ButtonResult.None;
  48. if (parameter?.ToLower() == "true")
  49. result = ButtonResult.OK;
  50. else if (parameter?.ToLower() == "false")
  51. result = ButtonResult.Cancel;
  52. RaiseRequestClose(new DialogResult(result));
  53. }
  54. public virtual void RaiseRequestClose(IDialogResult dialogResult)
  55. {
  56. RequestClose?.Invoke(dialogResult);
  57. }
  58. public bool CanCloseDialog()
  59. {
  60. return true;
  61. }
  62. public void OnDialogClosed()
  63. {
  64. }
  65. public void OnDialogOpened(IDialogParameters parameters)
  66. {
  67. Message = parameters.GetValue<string>("message");
  68. var isOK = parameters.GetValue<bool>("Type");
  69. if (isOK)
  70. {
  71. this.ErrorVisibillity = Visibility.Hidden;
  72. this.OKVisibillity = Visibility.Visible;
  73. }
  74. else
  75. {
  76. this.ErrorVisibillity = Visibility.Visible;
  77. this.OKVisibillity = Visibility.Hidden;
  78. }
  79. }
  80. }
  81. }