MainWindowViewModel.cs 1.7 KB

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