c# - C# .NetCore windows 通知?
问题描述
有没有办法从 .NetCore(3.1 版)程序中获取弹出菜单或侧边栏通知?
我尝试了 MessageBox 和 ToastNotification 等多种解决方案,但它们都不起作用。MessageBox 不允许我添加“使用”(不知何故它应该是可能的,但是它加载了一个多小时并且没有发生任何事情)并且 ToastNotification 只是没有给我任何回报....就像我没有收到错误,也没有通知和调试没有告诉我任何有用的价值...
解决方案
所以 ToastContentBuilder 不知何故不起作用。我假设 Builder 应该创建一个 XML,然后将其放入 ToastNotification。使用 .NetCore 3.1 不起作用(也许在其他一些框架中它可以工作)。所以解决这个问题的方法是自己创建 XML 文件。所以这里有一个人人都可以使用的功能。唯一需要编辑才能在其他代码中工作的是 .CreateToast 通知程序。您必须在此处输入项目的名称。
public static void showToastNotification(string toastText)
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
for (int i = 0; i < stringElements.Length; i++)
{
stringElements[i].AppendChild(toastXml.CreateTextNode(toastText));
}
ToastNotification toast = new ToastNotification(toastXml);
toast.Activated += Toast_Activated;
toast.Dismissed += Toast_Dismissed;
toast.Failed += Toast_Failed;
ToastNotificationManager.CreateToastNotifier("'Your project name'").Show(toast);
}
推荐阅读
- c# - 使用百分比创建对象动画
- java - 如何将 Maven 项目外部的文件添加到 ZIP 发行版?
- c# - 如何在 .net wpf 应用程序中支持来自精密触摸板的 2 指捏合/缩放手势?
- r - R:来自 e1071 预测的 svm 因“概率”参数设置而异
- python - Pandas:按项目在 DataFrame 中出现的次数过滤列
- python - 如何在不抓取文档本身的情况下从网页获取文件的下载链接?
- python-2.7 - 用于在树莓派上自动更改 crontab 启动的 Python 脚本
- apache-kafka - java.lang.IllegalArgumentException,同时将 SASL_PLAINTEXT 身份验证添加到 kafka 代理
- linux - 当从 hdi 工作节点运行时,hdfs 是否知道 umi 安全上下文?
- python - 我不断收到我的列表索引超出范围的错误