LinuxIntegration.Notifications
1.0.0
本機Linux桌面通知
標準dotnet構建過程, dotnet build
您可以從Nuget https://www.nuget.org/packages/rbnswartz.linuxintegration.notification/
創建一個通知manager的實例,並調用Adswotification Async
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 ) ;創建通知時獲取返回的ID,然後致電HidenotificationAsyAsync
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 ) ;如果通知系統支持它們,則可以將自定義操作添加到通知中。
您可以通過查看NotificationManager上的suptortations屬性來檢查它是否得到支持
如果支持動作,則可以這樣使用它們。字典的鍵是顯示的值,該值是單擊操作時將調用的操作
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 ) ;