Files
Ursa.Avalonia/demo/Ursa.Demo/ViewModels/PopConfirmDemoViewModel.cs
2025-04-18 02:37:27 +08:00

33 lines
947 B
C#

using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Controls.Notifications;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Ursa.Controls;
namespace Ursa.Demo.ViewModels;
public partial class PopConfirmDemoViewModel: ObservableObject
{
internal WindowToastManager? ToastManager { get; set; }
public ICommand ConfirmCommand { get; }
public ICommand CancelCommand { get; }
public PopConfirmDemoViewModel()
{
ConfirmCommand = new AsyncRelayCommand(OnConfirm);
CancelCommand = new RelayCommand(OnCancel);
}
private async Task OnConfirm()
{
await Task.Delay(3000);
ToastManager?.Show(new Toast("Confirmed"), type: NotificationType.Success, classes: ["Light"]);
}
private void OnCancel()
{
ToastManager?.Show(new Toast("Canceled"), type:NotificationType.Error, classes: ["Light"]);
}
}