feat: support uninstall.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
|
using Avalonia.LogicalTree;
|
||||||
using Avalonia.VisualTree;
|
using Avalonia.VisualTree;
|
||||||
using Ursa.Controls;
|
using Ursa.Controls;
|
||||||
using Ursa.Demo.ViewModels;
|
using Ursa.Demo.ViewModels;
|
||||||
@@ -26,13 +27,9 @@ public partial class NotificationDemo : UserControl
|
|||||||
_viewModel.NotificationManager = new WindowNotificationManager(_topLevel) { MaxItems = 3 };
|
_viewModel.NotificationManager = new WindowNotificationManager(_topLevel) { MaxItems = 3 };
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnDetachedFromVisualTree(e);
|
base.OnDetachedFromLogicalTree(e);
|
||||||
var adorner = _topLevel.FindDescendantOfType<VisualLayerManager>()?.AdornerLayer;
|
_viewModel.NotificationManager?.Uninstall();
|
||||||
if (adorner is not null && _viewModel.NotificationManager is not null)
|
|
||||||
{
|
|
||||||
adorner.Children.Remove(_viewModel.NotificationManager);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,6 +64,15 @@ public abstract class WindowMessageManager : TemplatedControl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void Uninstall()
|
||||||
|
{
|
||||||
|
if(Parent is AdornerLayer adornerLayer)
|
||||||
|
{
|
||||||
|
adornerLayer.Children.Remove(this);
|
||||||
|
AdornerLayer.SetAdornedElement(this, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void TopLevelOnTemplateApplied(object? sender, TemplateAppliedEventArgs e)
|
protected void TopLevelOnTemplateApplied(object? sender, TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
if (Parent is AdornerLayer adornerLayer)
|
if (Parent is AdornerLayer adornerLayer)
|
||||||
|
|||||||
Reference in New Issue
Block a user