mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect.git
synced 2025-06-24 13:34:13 +08:00
38 lines
983 B
C#
38 lines
983 B
C#
![]() |
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));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|