feat: add TryGetXXManager to WindowXXManager.

This commit is contained in:
Zhang Dian
2025-03-27 23:36:32 +08:00
parent f6f01ae1d9
commit 89b17752f3
8 changed files with 65 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ using Avalonia.Controls.Notifications;
using Avalonia.Controls.Primitives;
using Avalonia.Layout;
using Avalonia.Threading;
using Avalonia.VisualTree;
namespace Ursa.Controls;
@@ -69,6 +70,12 @@ public class WindowNotificationManager : WindowMessageManager, INotificationMana
VerticalAlignmentProperty.OverrideDefaultValue<WindowNotificationManager>(VerticalAlignment.Stretch);
}
public static bool TryGetNotificationManager(Visual? visual, out WindowNotificationManager? manager)
{
manager = visual?.FindDescendantOfType<WindowNotificationManager>();
return manager is not null;
}
/// <inheritdoc/>
public void Show(INotification content)
{

View File

@@ -84,6 +84,12 @@ public abstract class WindowMessageManager : TemplatedControl
}
}
public static bool TryGetMessageManager(Visual? visual, out WindowMessageManager? manager)
{
manager = visual?.FindDescendantOfType<WindowMessageManager>();
return manager is not null;
}
protected void TopLevelOnTemplateApplied(object? sender, TemplateAppliedEventArgs e)
{
if (Parent is AdornerLayer adornerLayer)

View File

@@ -1,7 +1,9 @@
using Avalonia.Controls;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
using Avalonia.Controls.Primitives;
using Avalonia.Threading;
using Avalonia.VisualTree;
namespace Ursa.Controls;
@@ -33,6 +35,12 @@ public class WindowToastManager : WindowMessageManager, IToastManager
{
}
public static bool TryGetToastManager(Visual? visual, out WindowToastManager? manager)
{
manager = visual?.FindDescendantOfType<WindowToastManager>();
return manager is not null;
}
/// <inheritdoc/>
public void Show(IToast content)
{