DialogsViewModel.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Avalonia.Controls;
  2. using Avalonia.Controls.Notifications;
  3. using SukiUI.Dialogs;
  4. using SukiUI.Toasts;
  5. using System;
  6. using System.Diagnostics.CodeAnalysis;
  7. namespace ShakerApp.ViewModels
  8. {
  9. public class DialogsViewModel
  10. {
  11. private string Caption => (string)(App.Current?.FindResource("PromptTitle") ?? "");
  12. private string Yes => (string)(App.Current?.FindResource("PromptYes") ?? "");
  13. private string No => (string)(App.Current?.FindResource("PromptNo") ?? "");
  14. [AllowNull]
  15. private ISukiDialogManager _DialogManager;
  16. public DialogsViewModel(ISukiDialogManager dialogManager)
  17. {
  18. _DialogManager = dialogManager;
  19. }
  20. public bool Error(string msg)
  21. {
  22. return _DialogManager.CreateDialog()
  23. .OfType(NotificationType.Error)
  24. .WithTitle(Caption)
  25. .WithContent(msg)
  26. .WithActionButton
  27. (Yes, _ => { }, true).TryShow();
  28. }
  29. public bool Ask(string msg,Action? yesaction=null,Action? noaction = null)
  30. {
  31. return _DialogManager.CreateDialog()
  32. .OfType(NotificationType.Information)
  33. .WithTitle(Caption)
  34. .WithContent(msg)
  35. .WithActionButton(Yes, _ => yesaction?.Invoke(), true)
  36. .WithActionButton(No, _ => noaction?.Invoke(),true)
  37. .TryShow();
  38. }
  39. public bool Info(string msg)
  40. {
  41. return _DialogManager.CreateDialog()
  42. .OfType(NotificationType.Information)
  43. .WithTitle(Caption)
  44. .WithContent(msg)
  45. .WithActionButton
  46. (Yes, _ => { }, true).TryShow();
  47. }
  48. public bool Success(string msg)
  49. {
  50. return _DialogManager.CreateDialog()
  51. .OfType(NotificationType.Success)
  52. .WithTitle(Caption)
  53. .WithContent(msg)
  54. .WithActionButton
  55. (Yes, _ => { }, true).TryShow();
  56. }
  57. public bool Warning(string msg)
  58. {
  59. return _DialogManager.CreateDialog()
  60. .OfType(NotificationType.Warning)
  61. .WithTitle(Caption)
  62. .WithContent(msg)
  63. .WithActionButton
  64. (Yes, _ => { }, true).TryShow();
  65. }
  66. }
  67. }