diff --git a/demo/Ursa.Demo/Dialogs/CustomDemoDialog.axaml.cs b/demo/Ursa.Demo/Dialogs/CustomDemoDialog.axaml.cs index c8353aa..7e5cd07 100644 --- a/demo/Ursa.Demo/Dialogs/CustomDemoDialog.axaml.cs +++ b/demo/Ursa.Demo/Dialogs/CustomDemoDialog.axaml.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Notifications; @@ -23,24 +24,14 @@ public partial class CustomDemoDialog : UserControl base.OnAttachedToVisualTree(e); _viewModel = this.DataContext as CustomDemoDialogViewModel; var visualLayerManager = this.FindAncestorOfType(); - if (visualLayerManager is not null && _viewModel is not null) - { - _viewModel.NotificationManager = new WindowNotificationManager(visualLayerManager) { MaxItems = 3 }; - _viewModel.ToastManager = new WindowToastManager(visualLayerManager) { MaxItems = 3 }; - } - - WindowNotificationManager.TryGetNotificationManager(visualLayerManager, out var manager); - if (manager is not null && _viewModel is not null) - { - Console.WriteLine(ReferenceEquals(_viewModel.NotificationManager, manager)); - manager.Position = NotificationPosition.TopCenter; - } - } - - protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) - { - base.OnDetachedFromVisualTree(e); - _viewModel?.NotificationManager?.Uninstall(); - _viewModel?.ToastManager?.Uninstall(); + 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 _)); } } \ No newline at end of file