feat: add VisualLayerManager ctor to Notification & Toast manager.
This commit is contained in:
@@ -75,6 +75,14 @@
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal"
|
||||
Spacing="8">
|
||||
<Button
|
||||
Command="{Binding ShowNotificationCommand}"
|
||||
Content="Notification"
|
||||
Theme="{DynamicResource SolidButton}" />
|
||||
<Button
|
||||
Command="{Binding ShowToastCommand}"
|
||||
Content="Toast"
|
||||
Theme="{DynamicResource SolidButton}" />
|
||||
<Button
|
||||
Command="{Binding DialogCommand}"
|
||||
Content="Dialog"
|
||||
|
||||
@@ -1,13 +1,36 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.VisualTree;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace Ursa.Demo.Dialogs;
|
||||
|
||||
public partial class CustomDemoDialog : UserControl
|
||||
{
|
||||
private CustomDemoDialogViewModel? _viewModel;
|
||||
|
||||
public CustomDemoDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
_viewModel = this.DataContext as CustomDemoDialogViewModel;
|
||||
var visualLayerManager = this.FindAncestorOfType<VisualLayerManager>();
|
||||
if (visualLayerManager is not null && _viewModel is not null)
|
||||
{
|
||||
_viewModel.NotificationManager = new WindowNotificationManager(visualLayerManager) { MaxItems = 3 };
|
||||
_viewModel.ToastManager = new WindowToastManager(visualLayerManager) { MaxItems = 3 };
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnDetachedFromVisualTree(e);
|
||||
_viewModel?.NotificationManager?.Uninstall();
|
||||
_viewModel?.ToastManager?.Uninstall();
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ public partial class CustomDemoDialogViewModel : ObservableObject, IDialogContex
|
||||
[ObservableProperty] private string? _department;
|
||||
[ObservableProperty] private string? _owner;
|
||||
[ObservableProperty] private string? _target;
|
||||
public WindowNotificationManager? NotificationManager { get; set; }
|
||||
public WindowToastManager? ToastManager { get; set; }
|
||||
|
||||
public CustomDemoDialogViewModel()
|
||||
{
|
||||
@@ -39,7 +41,6 @@ public partial class CustomDemoDialogViewModel : ObservableObject, IDialogContex
|
||||
|
||||
public ICommand OKCommand { get; set; }
|
||||
public ICommand CancelCommand { get; set; }
|
||||
|
||||
public ICommand DialogCommand { get; set; }
|
||||
|
||||
private void OK()
|
||||
@@ -54,6 +55,19 @@ public partial class CustomDemoDialogViewModel : ObservableObject, IDialogContex
|
||||
|
||||
private async Task ShowDialog()
|
||||
{
|
||||
await OverlayDialog.ShowCustomModal<CustomDemoDialog, CustomDemoDialogViewModel, bool>(new CustomDemoDialogViewModel());
|
||||
await OverlayDialog.ShowCustomModal<CustomDemoDialog, CustomDemoDialogViewModel, bool>(
|
||||
new CustomDemoDialogViewModel());
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ShowToast(object obj)
|
||||
{
|
||||
ToastManager?.Show("This is a Toast message");
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ShowNotification(object obj)
|
||||
{
|
||||
NotificationManager?.Show("This is a Notification message");
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Notifications;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Threading;
|
||||
|
||||
@@ -37,6 +38,14 @@ public class WindowNotificationManager : WindowMessageManager, INotificationMana
|
||||
set => SetValue(PositionProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WindowNotificationManager"/> class.
|
||||
/// </summary>
|
||||
public WindowNotificationManager()
|
||||
{
|
||||
UpdatePseudoClasses(Position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WindowNotificationManager"/> class.
|
||||
/// </summary>
|
||||
@@ -49,10 +58,7 @@ public class WindowNotificationManager : WindowMessageManager, INotificationMana
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WindowNotificationManager"/> class.
|
||||
/// </summary>
|
||||
public WindowNotificationManager()
|
||||
public WindowNotificationManager(VisualLayerManager? visualLayerManager) : base(visualLayerManager)
|
||||
{
|
||||
UpdatePseudoClasses(Position);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,17 @@ public abstract class WindowMessageManager : TemplatedControl
|
||||
VerticalAlignmentProperty.OverrideDefaultValue<WindowMessageManager>(VerticalAlignment.Stretch);
|
||||
}
|
||||
|
||||
public WindowMessageManager()
|
||||
{
|
||||
}
|
||||
|
||||
public WindowMessageManager(VisualLayerManager? visualLayerManager) : this()
|
||||
{
|
||||
if (visualLayerManager is null) return;
|
||||
visualLayerManager.AdornerLayer.Children.Add(this);
|
||||
AdornerLayer.SetAdornedElement(this, visualLayerManager.AdornerLayer);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Notifications;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Threading;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
@@ -9,6 +10,13 @@ namespace Ursa.Controls;
|
||||
/// </summary>
|
||||
public class WindowToastManager : WindowMessageManager, IToastManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WindowToastManager"/> class.
|
||||
/// </summary>
|
||||
public WindowToastManager()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WindowToastManager"/> class.
|
||||
/// </summary>
|
||||
@@ -21,10 +29,7 @@ public class WindowToastManager : WindowMessageManager, IToastManager
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WindowToastManager"/> class.
|
||||
/// </summary>
|
||||
public WindowToastManager()
|
||||
public WindowToastManager(VisualLayerManager? visualLayerManager) : base(visualLayerManager)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user