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