fix: remove Manager OnDetachedFromVisualTree.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.VisualTree;
|
||||
using Ursa.Controls;
|
||||
using Ursa.Demo.ViewModels;
|
||||
|
||||
@@ -8,6 +10,7 @@ namespace Ursa.Demo.Pages;
|
||||
public partial class NotificationDemo : UserControl
|
||||
{
|
||||
private NotificationDemoViewModel _viewModel;
|
||||
private TopLevel? _topLevel;
|
||||
|
||||
public NotificationDemo()
|
||||
{
|
||||
@@ -19,7 +22,17 @@ public partial class NotificationDemo : UserControl
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
_viewModel.NotificationManager = new WindowNotificationManager(topLevel) { MaxItems = 3 };
|
||||
_topLevel = TopLevel.GetTopLevel(this);
|
||||
_viewModel.NotificationManager = new WindowNotificationManager(_topLevel) { MaxItems = 3 };
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnDetachedFromVisualTree(e);
|
||||
var adorner = _topLevel.FindDescendantOfType<VisualLayerManager>()?.AdornerLayer;
|
||||
if (adorner is not null && _viewModel.NotificationManager is not null)
|
||||
{
|
||||
adorner.Children.Remove(_viewModel.NotificationManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user