using System; using System.Diagnostics; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Notifications; using Avalonia.Controls.Primitives; using Avalonia.VisualTree; using Ursa.Controls; using WindowNotificationManager = Ursa.Controls.WindowNotificationManager; namespace Ursa.Demo.Dialogs; public partial class CustomDemoDialog : UserControl { private CustomDemoDialogViewModel? _viewModel; public CustomDemoDialog() { InitializeComponent(); } protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { base.OnAttachedToVisualTree(e); _viewModel = this.DataContext as CustomDemoDialogViewModel; var visualLayerManager = this.FindAncestorOfType(); if (_viewModel == null) return; _viewModel.NotificationManager = WindowNotificationManager.TryGetNotificationManager(visualLayerManager, out var notificationManager) ? notificationManager : new WindowNotificationManager(visualLayerManager) { MaxItems = 3 }; _viewModel.ToastManager = WindowToastManager.TryGetToastManager(visualLayerManager, out var toastManager) ? toastManager : new WindowToastManager(visualLayerManager) { MaxItems = 3 }; Debug.Assert(WindowNotificationManager.TryGetNotificationManager(visualLayerManager, out _)); } }