From 243be53d04f2c7a8c72ce83e99fe13f5bc293385 Mon Sep 17 00:00:00 2001 From: Dong Bin Date: Fri, 28 Mar 2025 15:41:16 +0800 Subject: [PATCH] feat: ensure notification manager is initialized. --- demo/Ursa.Demo/Pages/NotificationDemo.axaml.cs | 11 +++++------ demo/Ursa.Demo/Views/MainView.axaml.cs | 10 +++++----- 2 files changed, 10 insertions(+), 11 deletions(-) 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