MainWindowViewModel.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Reactive;
  2. using System.Threading.Tasks;
  3. using Avalonia.Controls.Notifications;
  4. using Avalonia.Diagnostics.ViewModels;
  5. using Avalonia.Threading;
  6. using ReactiveUI;
  7. namespace ControlCatalog.ViewModels
  8. {
  9. class MainWindowViewModel : ViewModelBase
  10. {
  11. public MainWindowViewModel()
  12. {
  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 NotificationContent { Title = "Welcome", Message = "Avalonia now supports Notifications.", Type = NotificationType.Information });
  20. });
  21. ShowNativeNotificationCommand = ReactiveCommand.Create(() =>
  22. {
  23. NotificationManager.Show(new NotificationContent { Title = "Error", Message = "Native Notifications are not quite ready. Coming soon.", Type = NotificationType.Error });
  24. });
  25. }
  26. private INotificationManager _notificationManager;
  27. public INotificationManager NotificationManager
  28. {
  29. get { return _notificationManager; }
  30. set { this.RaiseAndSetIfChanged(ref _notificationManager, value); }
  31. }
  32. public ReactiveCommand<Unit, Unit> ShowCustomManagedNotificationCommand { get; }
  33. public ReactiveCommand<Unit, Unit> ShowManagedNotificationCommand { get; }
  34. public ReactiveCommand<Unit, Unit> ShowNativeNotificationCommand { get; }
  35. }
  36. }