feat: enhancement.

This commit is contained in:
Zhang Dian
2024-09-12 18:48:26 +08:00
parent ea385ee194
commit 850339f324
3 changed files with 6 additions and 16 deletions

View File

@@ -1,8 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.LogicalTree;
using Avalonia.VisualTree;
using Ursa.Controls;
using Ursa.Demo.ViewModels;
@@ -11,7 +9,6 @@ namespace Ursa.Demo.Pages;
public partial class NotificationDemo : UserControl
{
private NotificationDemoViewModel _viewModel;
private TopLevel? _topLevel;
public NotificationDemo()
{
@@ -23,8 +20,8 @@ public partial class NotificationDemo : UserControl
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
_topLevel = TopLevel.GetTopLevel(this);
_viewModel.NotificationManager = new WindowNotificationManager(_topLevel) { MaxItems = 3 };
var topLevel = TopLevel.GetTopLevel(this);
_viewModel.NotificationManager = new WindowNotificationManager(topLevel) { MaxItems = 3 };
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)

View File

@@ -1,7 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.VisualTree;
using Ursa.Controls;
using Ursa.Demo.ViewModels;
@@ -10,7 +8,6 @@ namespace Ursa.Demo.Pages;
public partial class ToastDemo : UserControl
{
private ToastDemoViewModel _viewModel;
private TopLevel? _topLevel;
public ToastDemo()
{
@@ -22,17 +19,13 @@ public partial class ToastDemo : UserControl
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
_topLevel = TopLevel.GetTopLevel(this);
_viewModel.ToastManager = new WindowToastManager(_topLevel) { MaxItems = 3 };
var topLevel = TopLevel.GetTopLevel(this);
_viewModel.ToastManager = new WindowToastManager(topLevel) { MaxItems = 3 };
}
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
var adorner = _topLevel.FindDescendantOfType<VisualLayerManager>()?.AdornerLayer;
if (adorner is not null && _viewModel.ToastManager is not null)
{
adorner.Children.Remove(_viewModel.ToastManager);
}
_viewModel.ToastManager?.Uninstall();
}
}