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,11 +1,28 @@
using Avalonia;
using Avalonia.Controls;
using Ursa.Controls;
using Ursa.Demo.ViewModels;
namespace Ursa.Demo.Views;
public partial class MainView : UserControl
{
private MainViewViewModel? _viewModel;
public MainView()
{
InitializeComponent();
}
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
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;
}
}
}

View File

@@ -5,9 +5,12 @@ namespace Ursa.Demo.Views;
public partial class MainWindow : UrsaWindow
{
public WindowNotificationManager? NotificationManager { get; set; }
public MainWindow()
{
InitializeComponent();
NotificationManager = new WindowNotificationManager(this) { MaxItems = 3 };
}
protected override async Task<bool> CanClose()