简体   繁体   English

C#.NetCore windows 通知?

[英]C# .NetCore windows Notification?

Is there a way to get a Popup Menue or a side-bar Notification from a.NetCore (version 3.1) Programm?有没有办法从 a.NetCore(3.1 版)程序中获取弹出菜单或侧边栏通知?

I tried mulitple solutions like MessageBox and ToastNotification but none of them work.我尝试了 MessageBox 和 ToastNotification 等多种解决方案,但它们都不起作用。 MessageBox doesnt let me add "using" (somehow it should be possible but its loading for over an hour and nothing happpens) and ToastNotification just doesnt give me back anything.... like i get no error and no Notification and debugging doesnt tell me any useful values... MessageBox 不允许我添加“使用”(不知何故它应该是可能的,但是它加载了一个多小时并且没有发生任何事情)并且 ToastNotification 只是没有给我任何东西....就像我没有收到错误和没有通知和调试没有告诉我任何有用的价值...

在此处输入图像描述

So the ToastContentBuilder somehow doesn't work.所以 ToastContentBuilder 不知何故不起作用。 I assume the Builder is supposed to create a XML, that is then thrown into the ToastNotification.我假设 Builder 应该创建一个 XML,然后将其放入 ToastNotification。 With.NetCore 3.1 that doesn't work (maybe in some other frameworks it works).使用 .NetCore 3.1 不起作用(可能在其他一些框架中它起作用)。 So the solution to that problem is to create the XML file by yourself.所以解决这个问题的方法是自己创建 XML 文件。 So here is a function that everyone can use.所以这里有一个大家可以用的function。 The only thing that has to be edited so that it work in other codes is at.CreateToast Notifier.唯一需要编辑才能在其他代码中工作的是 at.CreateToast Notifier。 There you have to enter the name of your project.您必须在此处输入项目的名称。

 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);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM