Notifications de bureau Linux natives
Processus de construction standard DOTNET, dotnet build
Vous pouvez installer ce package à partir de Nuget https://www.nuget.org/packages/rbnswartz.linuxintegration.notifications/
Créez une instance de NotificationManager et Call affiché
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 ) ;Obtenez l'ID retourné lorsque vous avez créé la notification, puis appelez 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 ) ;Des actions personnalisées peuvent être ajoutées à une notification si le système de notification les prend en charge.
Vous pouvez vérifier s'il est pris en charge en examinant la propriété SupportSactions sur NotificationManager
Si les actions sont prises en charge, vous pouvez les utiliser comme ceci. La clé du dictionnaire est la valeur affichée et la valeur est une action qui sera appelée lorsque l'action est cliquée
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 ) ;