detect/detect.gui/Classes/NotificationService.cs

38 lines
983 B
C#
Raw Normal View History

2024-11-13 17:09:15 +08:00
using System;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
namespace detect.gui.Classes;
public abstract class NotificationService
{
private static WindowNotificationManager? _notificationManager;
private const int NotificationTimeout = 4;
public static void SetHostWindow(TopLevel? window)
{
var notificationManager = new WindowNotificationManager(window)
{
Position = NotificationPosition.BottomRight,
MaxItems = 4
};
_notificationManager = notificationManager;
}
public static void Show(string title, string? message, NotificationType type,Action? onClick = null)
{
if (_notificationManager is { } nm)
{
nm.Show(
new Notification(
title,
message,
type,
new TimeSpan(0,0,0, NotificationTimeout),
onClick));
}
}
}