diff --git a/demo/Ursa.Demo/Pages/NotificationDemo.axaml.cs b/demo/Ursa.Demo/Pages/NotificationDemo.axaml.cs index ccdb5d0..53f5e65 100644 --- a/demo/Ursa.Demo/Pages/NotificationDemo.axaml.cs +++ b/demo/Ursa.Demo/Pages/NotificationDemo.axaml.cs @@ -20,11 +20,10 @@ public partial class NotificationDemo : UserControl { base.OnAttachedToVisualTree(e); var topLevel = TopLevel.GetTopLevel(this); - - WindowNotificationManager.TryGetNotificationManager(topLevel, out var manager); - if (manager is not null) - { - _viewModel.NotificationManager = manager; - } + if (topLevel is null) + return; + _viewModel.NotificationManager = WindowNotificationManager.TryGetNotificationManager(topLevel, out var manager) + ? manager + : new WindowNotificationManager(topLevel); } } \ No newline at end of file diff --git a/demo/Ursa.Demo/Views/MainView.axaml.cs b/demo/Ursa.Demo/Views/MainView.axaml.cs index c7353e1..9cb2b0d 100644 --- a/demo/Ursa.Demo/Views/MainView.axaml.cs +++ b/demo/Ursa.Demo/Views/MainView.axaml.cs @@ -19,10 +19,10 @@ public partial class MainView : UserControl base.OnAttachedToVisualTree(e); _viewModel = DataContext as MainViewViewModel; var topLevel = TopLevel.GetTopLevel(this); - WindowNotificationManager.TryGetNotificationManager(topLevel, out var manager); - if (manager is not null && _viewModel is not null) - { - _viewModel.NotificationManager = manager; - } + if (topLevel is null || _viewModel is null) + return; + _viewModel.NotificationManager = WindowNotificationManager.TryGetNotificationManager(topLevel, out var manager) + ? manager + : new WindowNotificationManager(topLevel); } } \ No newline at end of file