Notificaciones nativas de escritorio de Linux
Proceso de compilación de dotnet estándar, dotnet build
Puede instalar este paquete desde nuget https://www.nuget.org/packages/rbnswartz.linuxintegration.notifications/
Cree una instancia de NotificationManager y llame a ShowsOtificationAsync
NotificationManager manager = new NotificationManager ( "test app" ) ;
var summary = "This is a summary" ;
var body = "This is the body of the notification" ;
await manager . ShowNotificationAsync ( summary , body , expiration : 5000 ) ;Obtenga la identificación devuelta cuando creó la notificación y luego llame a HidenotificationAsync
NotificationManager manager = new NotificationManager ( "test app" ) ;
var summary = "This is a summary" ;
var body = "This is the body of the notification" ;
var id = await manager . ShowNotificationAsync ( summary , body , expiration : 5000 ) ;
await manager . HideNotificationAsync ( id ) ;Se pueden agregar acciones personalizadas a una notificación si el sistema de notificación las admite.
Puede verificar si es compatible mirando la propiedad SupportSactions en NotificationManager
Si se admiten acciones, puede usarlas así. La clave del diccionario es el valor mostrado y el valor es una acción que se llamará cuando se hace clic en la acción
NotificationManager manager = new NotificationManager ( "test app" ) ;
var summary = "This is a summary" ;
var body = "This is the body of the notification" ;
var notificationId = await manager . ShowNotificationAsync ( summary , body , actions : new Dictionary < string , Action > ( )
{
[ "Press me" ] = ( ) => Console . WriteLine ( "Press me action called" ) ,
[ "Do other important thing" ] = ( ) => Console . WriteLine ( "Other important thing" )
} ,
expiration : 5000 ) ;