fix: remove Manager OnDetachedFromVisualTree.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
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;
|
||||||
|
|
||||||
@@ -8,6 +10,7 @@ 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()
|
||||||
{
|
{
|
||||||
@@ -19,7 +22,17 @@ public partial class NotificationDemo : UserControl
|
|||||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnAttachedToVisualTree(e);
|
base.OnAttachedToVisualTree(e);
|
||||||
var topLevel = TopLevel.GetTopLevel(this);
|
_topLevel = TopLevel.GetTopLevel(this);
|
||||||
_viewModel.NotificationManager = new WindowNotificationManager(topLevel) { MaxItems = 3 };
|
_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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
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;
|
||||||
|
|
||||||
@@ -8,6 +10,7 @@ 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()
|
||||||
{
|
{
|
||||||
@@ -19,7 +22,17 @@ public partial class ToastDemo : UserControl
|
|||||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnAttachedToVisualTree(e);
|
base.OnAttachedToVisualTree(e);
|
||||||
var topLevel = TopLevel.GetTopLevel(this);
|
_topLevel = TopLevel.GetTopLevel(this);
|
||||||
_viewModel.ToastManager = new WindowToastManager(topLevel) { MaxItems = 3 };
|
_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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ public class MenuViewModel: ViewModelBase
|
|||||||
new() { MenuHeader = "Message Box", Key = MenuKeys.MenuKeyMessageBox },
|
new() { MenuHeader = "Message Box", Key = MenuKeys.MenuKeyMessageBox },
|
||||||
new() { MenuHeader = "MultiComboBox", Key = MenuKeys.MenuKeyMultiComboBox, Status = "Updated" },
|
new() { MenuHeader = "MultiComboBox", Key = MenuKeys.MenuKeyMultiComboBox, Status = "Updated" },
|
||||||
new() { MenuHeader = "Nav Menu", Key = MenuKeys.MenuKeyNavMenu },
|
new() { MenuHeader = "Nav Menu", Key = MenuKeys.MenuKeyNavMenu },
|
||||||
new() { MenuHeader = "Notification", Key = MenuKeys.MenuKeyNotification },
|
new() { MenuHeader = "Notification", Key = MenuKeys.MenuKeyNotification, Status = "New"},
|
||||||
new() { MenuHeader = "Number Displayer", Key = MenuKeys.MenuKeyNumberDisplayer, Status = "New" },
|
new() { MenuHeader = "Number Displayer", Key = MenuKeys.MenuKeyNumberDisplayer, Status = "New" },
|
||||||
new() { MenuHeader = "Numeric UpDown", Key = MenuKeys.MenuKeyNumericUpDown },
|
new() { MenuHeader = "Numeric UpDown", Key = MenuKeys.MenuKeyNumericUpDown },
|
||||||
new() { MenuHeader = "NumPad", Key = MenuKeys.MenuKeyNumPad },
|
new() { MenuHeader = "NumPad", Key = MenuKeys.MenuKeyNumPad },
|
||||||
@@ -54,7 +54,7 @@ public class MenuViewModel: ViewModelBase
|
|||||||
new() { MenuHeader = "Timeline", Key = MenuKeys.MenuKeyTimeline },
|
new() { MenuHeader = "Timeline", Key = MenuKeys.MenuKeyTimeline },
|
||||||
new() { MenuHeader = "TreeComboBox", Key = MenuKeys.MenuKeyTreeComboBox },
|
new() { MenuHeader = "TreeComboBox", Key = MenuKeys.MenuKeyTreeComboBox },
|
||||||
new() { MenuHeader = "TwoTonePathIcon", Key = MenuKeys.MenuKeyTwoTonePathIcon},
|
new() { MenuHeader = "TwoTonePathIcon", Key = MenuKeys.MenuKeyTwoTonePathIcon},
|
||||||
new() { MenuHeader = "Toast", Key = MenuKeys.MenuKeyToast },
|
new() { MenuHeader = "Toast", Key = MenuKeys.MenuKeyToast, Status = "New"},
|
||||||
new() { MenuHeader = "ToolBar", Key = MenuKeys.MenuKeyToolBar },
|
new() { MenuHeader = "ToolBar", Key = MenuKeys.MenuKeyToolBar },
|
||||||
new() { MenuHeader = "Time Box", Key = MenuKeys.MenuKeyTimeBox },
|
new() { MenuHeader = "Time Box", Key = MenuKeys.MenuKeyTimeBox },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -196,19 +196,19 @@ public abstract class MessageCard : ContentControl
|
|||||||
{
|
{
|
||||||
switch (NotificationType)
|
switch (NotificationType)
|
||||||
{
|
{
|
||||||
case Avalonia.Controls.Notifications.NotificationType.Error:
|
case NotificationType.Error:
|
||||||
PseudoClasses.Add(PC_Error);
|
PseudoClasses.Add(PC_Error);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Avalonia.Controls.Notifications.NotificationType.Information:
|
case NotificationType.Information:
|
||||||
PseudoClasses.Add(PC_Information);
|
PseudoClasses.Add(PC_Information);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Avalonia.Controls.Notifications.NotificationType.Success:
|
case NotificationType.Success:
|
||||||
PseudoClasses.Add(PC_Success);
|
PseudoClasses.Add(PC_Success);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Avalonia.Controls.Notifications.NotificationType.Warning:
|
case NotificationType.Warning:
|
||||||
PseudoClasses.Add(PC_Warning);
|
PseudoClasses.Add(PC_Warning);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user