NotificationsPage.xaml.cs 838 B

123456789101112131415161718192021222324252627282930313233
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Controls.Notifications;
  4. using ControlCatalog.ViewModels;
  5. namespace ControlCatalog.Pages
  6. {
  7. public partial class NotificationsPage : UserControl
  8. {
  9. private NotificationViewModel _viewModel;
  10. public NotificationsPage()
  11. {
  12. InitializeComponent();
  13. _viewModel = new NotificationViewModel();
  14. DataContext = _viewModel;
  15. }
  16. protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
  17. {
  18. base.OnAttachedToVisualTree(e);
  19. _viewModel.NotificationManager = new WindowNotificationManager(TopLevel.GetTopLevel(this)!);
  20. }
  21. public void NotificationOnClick()
  22. {
  23. ControlNotifications.Show("Notification clicked");
  24. }
  25. }
  26. }