1
0

MainWindowViewModel.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using Avalonia;
  6. using Avalonia.Controls.Notifications;
  7. using Avalonia.Diagnostics.ViewModels;
  8. using Avalonia.Threading;
  9. using ReactiveUI;
  10. namespace ControlCatalog.ViewModels
  11. {
  12. class MainWindowViewModel : ViewModelBase
  13. {
  14. public MainWindowViewModel()
  15. {
  16. this.WhenAnyValue(x => x.NotificationManager).Subscribe(x =>
  17. {
  18. });
  19. Dispatcher.UIThread.InvokeAsync(async () =>
  20. {
  21. await Task.Delay(5000);
  22. NotificationManager.Show(new NotificationViewModel { Title = "Warning", Message = "Please save your work before closing." });
  23. await Task.Delay(1500);
  24. NotificationManager.Show(new NotificationContent { Message = "Test2", Type = NotificationType.Error });
  25. await Task.Delay(2000);
  26. NotificationManager.Show(new NotificationContent { Message = "Test3", Type = NotificationType.Warning });
  27. await Task.Delay(2500);
  28. NotificationManager.Show(new NotificationContent { Message = "Test4", Type = NotificationType.Success });
  29. await Task.Delay(500);
  30. NotificationManager.Show("Test5");
  31. });
  32. }
  33. private INotificationManager _notificationManager;
  34. public INotificationManager NotificationManager
  35. {
  36. get { return _notificationManager; }
  37. set { this.RaiseAndSetIfChanged(ref _notificationManager, value); }
  38. }
  39. }
  40. }