MainWindowViewModel.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Reactive;
  2. using Avalonia.Controls.Notifications;
  3. using ReactiveUI;
  4. namespace ControlCatalog.ViewModels
  5. {
  6. class MainWindowViewModel : ReactiveObject
  7. {
  8. private IManagedNotificationManager _notificationManager;
  9. public MainWindowViewModel(IManagedNotificationManager notificationManager)
  10. {
  11. _notificationManager = notificationManager;
  12. ShowCustomManagedNotificationCommand = ReactiveCommand.Create(() =>
  13. {
  14. NotificationManager.Show(new NotificationViewModel(NotificationManager) { Title = "Hey There!", Message = "Did you know that Avalonia now supports Custom In-Window Notifications?" });
  15. });
  16. ShowManagedNotificationCommand = ReactiveCommand.Create(() =>
  17. {
  18. NotificationManager.Show(new Avalonia.Controls.Notifications.Notification("Welcome", "Avalonia now supports Notifications.", NotificationType.Information));
  19. });
  20. ShowNativeNotificationCommand = ReactiveCommand.Create(() =>
  21. {
  22. NotificationManager.Show(new Avalonia.Controls.Notifications.Notification("Error", "Native Notifications are not quite ready. Coming soon.", NotificationType.Error));
  23. });
  24. }
  25. public IManagedNotificationManager NotificationManager
  26. {
  27. get { return _notificationManager; }
  28. set { this.RaiseAndSetIfChanged(ref _notificationManager, value); }
  29. }
  30. public ReactiveCommand<Unit, Unit> ShowCustomManagedNotificationCommand { get; }
  31. public ReactiveCommand<Unit, Unit> ShowManagedNotificationCommand { get; }
  32. public ReactiveCommand<Unit, Unit> ShowNativeNotificationCommand { get; }
  33. }
  34. }