Is it possible to send Toast notification from console application?(是否可以从控制台应用程序发送 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 - 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
现在您需要添加此代码:
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);
参考:如何从 C# 桌面应用程序调用 Windows 8 中的 WinRT API - WinRT 图一个>
这篇关于是否可以从控制台应用程序发送 Toast 通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以从控制台应用程序发送 Toast 通知?


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01