feat: add TryGetXXManager to WindowXXManager.

This commit is contained in:
Zhang Dian
2025-03-27 23:36:32 +08:00
parent f6f01ae1d9
commit 89b17752f3
8 changed files with 65 additions and 9 deletions

View File

@@ -1,6 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.LogicalTree;
using Ursa.Controls;
using Ursa.Demo.ViewModels;
@@ -21,12 +20,11 @@ public partial class NotificationDemo : UserControl
{
base.OnAttachedToVisualTree(e);
var topLevel = TopLevel.GetTopLevel(this);
_viewModel.NotificationManager = new WindowNotificationManager(topLevel) { MaxItems = 3 };
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
_viewModel.NotificationManager?.Uninstall();
WindowNotificationManager.TryGetNotificationManager(topLevel, out var manager);
if (manager is not null)
{
_viewModel.NotificationManager = manager;
}
}
}