feat: ensure notification manager is initialized.

This commit is contained in:
Dong Bin
2025-03-28 15:41:16 +08:00
parent d30de5e7cd
commit 243be53d04
2 changed files with 10 additions and 11 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}