1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using Avalonia.Controls;
- using Avalonia.Controls.Notifications;
- using SukiUI.Dialogs;
- using SukiUI.Toasts;
- using System;
- using System.Diagnostics.CodeAnalysis;
- namespace ShakerApp.ViewModels
- {
- public class DialogsViewModel
- {
- private string Caption => (string)(App.Current?.FindResource("PromptTitle") ?? "");
- private string Yes => (string)(App.Current?.FindResource("PromptYes") ?? "");
- private string No => (string)(App.Current?.FindResource("PromptNo") ?? "");
- [AllowNull]
- private ISukiDialogManager _DialogManager;
- public DialogsViewModel(ISukiDialogManager dialogManager)
- {
- _DialogManager = dialogManager;
- }
- public bool Error(string msg)
- {
- return _DialogManager.CreateDialog()
- .OfType(NotificationType.Error)
- .WithTitle(Caption)
- .WithContent(msg)
- .WithActionButton
- (Yes, _ => { }, true).TryShow();
- }
- public bool Ask(string msg,Action? yesaction=null,Action? noaction = null)
- {
- return _DialogManager.CreateDialog()
- .OfType(NotificationType.Information)
- .WithTitle(Caption)
- .WithContent(msg)
- .WithActionButton(Yes, _ => yesaction?.Invoke(), true)
- .WithActionButton(No, _ => noaction?.Invoke(),true)
- .TryShow();
- }
- public bool Info(string msg)
- {
- return _DialogManager.CreateDialog()
- .OfType(NotificationType.Information)
- .WithTitle(Caption)
- .WithContent(msg)
- .WithActionButton
- (Yes, _ => { }, true).TryShow();
- }
- public bool Success(string msg)
- {
- return _DialogManager.CreateDialog()
- .OfType(NotificationType.Success)
- .WithTitle(Caption)
- .WithContent(msg)
- .WithActionButton
- (Yes, _ => { }, true).TryShow();
- }
- public bool Warning(string msg)
- {
- return _DialogManager.CreateDialog()
- .OfType(NotificationType.Warning)
- .WithTitle(Caption)
- .WithContent(msg)
- .WithActionButton
- (Yes, _ => { }, true).TryShow();
- }
- }
- }
|