MainWindowViewModel.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Threading.Tasks;
  2. using Avalonia.Controls.Notifications;
  3. using Avalonia.Diagnostics.ViewModels;
  4. using Avalonia.Threading;
  5. namespace ControlCatalog.ViewModels
  6. {
  7. class MainWindowViewModel : ViewModelBase
  8. {
  9. public MainWindowViewModel()
  10. {
  11. Dispatcher.UIThread.InvokeAsync(async () =>
  12. {
  13. await Task.Delay(5000);
  14. NotificationManager.Show(new NotificationViewModel (NotificationManager) { Title = "Warning", Message = "Did you know that Avalonia now supports Notifications?" });
  15. await Task.Delay(1500);
  16. NotificationManager.Show(new NotificationContent { Title= "Title", Message = "Test2", Type = NotificationType.Error });
  17. await Task.Delay(2000);
  18. NotificationManager.Show(new NotificationContent { Title = "Title", Message = "Test3", Type = NotificationType.Warning });
  19. await Task.Delay(2500);
  20. NotificationManager.Show(new NotificationContent { Title = "Title", Message = "Test4", Type = NotificationType.Success });
  21. await Task.Delay(500);
  22. NotificationManager.Show("Test5");
  23. });
  24. }
  25. private INotificationManager _notificationManager;
  26. public INotificationManager NotificationManager
  27. {
  28. get { return _notificationManager; }
  29. set { this.RaiseAndSetIfChanged(ref _notificationManager, value); }
  30. }
  31. }
  32. }