Native Linux -Desktop -Benachrichtigungen
Standard -Dotnet -Build -Prozess, dotnet build
Sie können dieses Paket von nuget https://www.nuget.org/packages/rbnswartz.linuxintegration.notifications/ installieren
Erstellen Sie eine Instanz von NotificationManager und Aufrufen von tecalificationAsync
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 ) ;Holen Sie sich die zurückgegebene ID, wenn Sie die Benachrichtigung erstellt haben, und rufen Sie dann HidenotificationAsync auf
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 ) ;Zu einer Benachrichtigung können benutzerdefinierte Aktionen hinzugefügt werden, wenn das Benachrichtigungssystem sie unterstützt.
Sie können prüfen, ob es unterstützt wird, indem Sie sich die Supportsactions -Eigenschaft auf NotificationManager ansehen
Wenn Aktionen unterstützt werden, können Sie sie so verwenden. Der Schlüssel des Wörterbuchs ist der angezeigte Wert und der Wert ist eine Aktion, die aufgerufen wird, wenn die Aktion geklickt wird
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 ) ;