是否可以从控制台应用程序发送Toast通知?
是否可以使用 ToastNotificationManager 从控制台应用程序发送Toast通知?
Is it possible to send Toast notifications from console application using ToastNotificationManager ?
我知道可以从Windows发送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-以XML字符串存储的Toast
*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实际上使用了before。在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,选择卸载项目
- 右键单击yourProject(不可用),然后单击编辑yourProject.csproj
- 添加新的属性组:
< targetplatformversion> 8.0< / targetplatformversion>
- 重新加载项目
- 从 Windows>核心
- Right-click on your yourProject, select Unload Project
- Right-click on your yourProject(unavailable) and click Edit yourProject.csproj
- Add a new property group:
<targetplatformversion>8.0</targetplatformversion>
- Reload project
- Add reference Windows from Windows > Core
现在您需要添加以下代码:
Now you need to add this code:
using Windows.UI.Notifications;
,您将可以使用以下代码发送通知:
and you will be able to send notifications using this code:
var toast = new ToastNotification(doc);
ToastNotificationManager.CreateToastNotifier().Show(toast);