From 7514d7085c8b60583d59de86d5d87048197e3eec Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 13 Jul 2023 16:02:43 +0200 Subject: [PATCH] Added an option to specify classes --- .../Notifications/IManagedNotificationManager.cs | 4 +++- .../Notifications/WindowNotificationManager.cs | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Notifications/IManagedNotificationManager.cs b/src/Avalonia.Controls/Notifications/IManagedNotificationManager.cs index 8d1cb644be..5eba36dbe6 100644 --- a/src/Avalonia.Controls/Notifications/IManagedNotificationManager.cs +++ b/src/Avalonia.Controls/Notifications/IManagedNotificationManager.cs @@ -23,10 +23,12 @@ namespace Avalonia.Controls.Notifications /// the expiration time of the notification after which it will automatically close. If the value is then the notification will remain open until the user closes it. /// an Action to be run when the notification is clicked. /// an Action to be run when the notification is closed. + /// Style-classes to ba added to the notification card void Show(object content, NotificationType type = NotificationType.Information, TimeSpan? expiration = null, Action? onClick = null, - Action? onClose = null); + Action? onClose = null, + string[]? classes = null); } } diff --git a/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs b/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs index d764f2bd78..0b7a19707b 100644 --- a/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs +++ b/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs @@ -88,7 +88,8 @@ namespace Avalonia.Controls.Notifications NotificationType type = NotificationType.Information, TimeSpan? expiration = null, Action? onClick = null, - Action? onClose = null) + Action? onClose = null, + string[]? classes = null) { var notificationControl = new NotificationCard { @@ -96,6 +97,15 @@ namespace Avalonia.Controls.Notifications NotificationType = type }; + // Add style classes if any + if (classes != null) + { + foreach (var @class in classes) + { + notificationControl.Classes.Add(@class); + } + } + notificationControl.NotificationClosed += (sender, args) => { onClose?.Invoke();