問題描述
是否可以使用 ToastNotificationManager 從控制臺應用程序發(fā)送 Toast 通知?
Is it possible to send Toast notifications from console application using ToastNotificationManager ?
我知道可以從 Windows 通用應用程序發(fā)送 Toast 通知:
I know that it is possible to send Toast notifications from Windows Universal app:
var toast = new ToastNotification(doc);
ToastNotificationManager.CreateToastNotifier().Show(toast);
*doc - Toast 存儲在 XML 字符串中
*doc - Toast stored in XML string
要使用 ToastNotificaionManager,我需要在控制臺應用程序項目中無法引用的 Windows.UI.Notifications 庫.
To use ToastNotificaionManager I need Windows.UI.Notifications library which I can't reference in console application project.
我之前提到的庫實際上是由 WinRT 使用的.是否可以在 Windows 控制臺應用程序中使用 WinRT API?
The library I mentionet before is actualy used by WinRT. Is it possible to use WinRT APIs in Windows console application ?
推薦答案
首先你需要聲明你的程序將使用 winRT 庫:
At first you need to declare that your program will be using winRT libraries:
- 右鍵單擊您的項目,選擇卸載項目
- 右鍵單擊您的項目(不可用),然后單擊編輯 yourProject.csproj
- 添加新的屬性組:
8.0 - 重新加載項目
- 從 Windows > Core
添加參考 Windows
現(xiàn)在您需要添加此代碼:
Now you need to add this code:
using Windows.UI.Notifications;
您將能夠使用此代碼發(fā)送通知:
and you will be able to send notifications using this code:
var toast = new ToastNotification(doc);
ToastNotificationManager.CreateToastNotifier().Show(toast);
參考:如何從 C# 桌面應用程序調用 Windows 8 中的 WinRT API - WinRT 圖一個>
這篇關于是否可以從控制臺應用程序發(fā)送 Toast 通知?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!