Browse Source

Added an option to specify classes

pull/12178/head
Tim 3 years ago
parent
commit
7514d7085c
  1. 4
      src/Avalonia.Controls/Notifications/IManagedNotificationManager.cs
  2. 12
      src/Avalonia.Controls/Notifications/WindowNotificationManager.cs

4
src/Avalonia.Controls/Notifications/IManagedNotificationManager.cs

@ -23,10 +23,12 @@ namespace Avalonia.Controls.Notifications
/// <param name="expiration">the expiration time of the notification after which it will automatically close. If the value is <see cref="TimeSpan.Zero"/> then the notification will remain open until the user closes it.</param>
/// <param name="onClick">an Action to be run when the notification is clicked.</param>
/// <param name="onClose">an Action to be run when the notification is closed.</param>
/// <param name="classes">Style-classes to ba added to the notification card</param>
void Show(object content,
NotificationType type = NotificationType.Information,
TimeSpan? expiration = null,
Action? onClick = null,
Action? onClose = null);
Action? onClose = null,
string[]? classes = null);
}
}

12
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();

Loading…
Cancel
Save