c# – 使用桌面应用程序在Windows 10上发出通知
我在C#中使用NotifyIcon获得了一个
Windows Forms项目.我正在使用以下代码显示气球通知:
notifyIcon.ShowBalloonTip(1000,"title","text",ToolTipIcon.Info); 这工作正常,直到Windows 8.1.现在我已经安装了Windows 10预览版,并且气球通知不再显示. 我想所有的通知都会被移动到Windows 8风格的Toast通知中,并且气球通知被完全删除(因为我还没有看到一个气球通知,还有更多的Toast通知),但我还没有找到官方来源这个呢. 问题是我的应用程序只是一个.exe文件,所以它没有安装程序或快捷方式.根据this页面,需要一个创建快捷方式的安装程序才能使Toast通知正常工作. 如何在没有任何快捷方式或安装程序的情况下在Windows 10中显示通知(我不在乎它是气球还是吐司通知)? 解决方法
我用这个帖子来帮助制作这段代码 – 我正在分享我的成功.
警告我是C#的新手,所以我的代码可能很糟糕 – 但它确实有用并且相当简单,而且对于我找到的大多数解决方案而言,这比我能说的还多 此外,我还有一段时间来阅读xml文档.我正在使用System.xml(我认为)和Windows.Data.Dom.Xml(也不完全确定). /* At first you need to declare that your program will be using winRT libraries: 1. Right click on your yourProject,select Unload Project 2. Right click on your youProject(unavailable) and click Edit yourProject.csproj 3. Add a new property group:<TargetPlatformVersion>8.0</TargetPlatformVersion> 4. Reload project 5. Add referece Windows from Windows > Core */ using System; using Windows.Data.Xml.Dom; using Windows.Storage; using Windows.Storage.Streams; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Windows.UI.Notifications; namespace ConsoleApplication6 { public class NewToastNotification { public NewToastNotification(string input,int type) { string NotificationTextThing = input; string Toast = ""; switch (type) { case 1: { //Basic Toast Toast = "<toast><visual><binding template="ToastImageAndText01"><text id = "1" >"; Toast += NotificationTextThing; Toast += "</text></binding></visual></toast>"; break; } default: { Toast = "<toast><visual><binding template="ToastImageAndText01"><text id = "1" >"; Toast += "Default Text String"; Toast += "</text></binding></visual></toast>"; break; } } XmlDocument tileXml = new XmlDocument(); tileXml.LoadXml(Toast); var toast = new ToastNotification(tileXml); ToastNotificationManager.CreateToastNotifier("New Toast Thing").Show(toast); } } class Program { static void Main(string[] args) { NewToastNotification Window = new NewToastNotification("Yes",1); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |