像win8这样的吐司通知 [英] toast notifications like win8

查看:80
本文介绍了像win8这样的吐司通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道是否可以使用吐司通知(类似于notifyicon但是Windows 8.1风格)



我正在使用c#4.0 / visual c#2010 express /桌面应用程序(不是WPF)

是否可以使用?怎么回事?

anyone know if it is possible to use toast notification (its like notifyicon but windows 8.1 style)

I'm using c#4.0 / visual c# 2010 express / desktop app (not WPF)
is possible to use? how is it?

推荐答案

不是没有第三方库。



您通常会通过参考WinRT运行时 [ ^ ],然后制作API调用以显示吐司:

Not without third-party libraries.

You would normally do this by referencing the WinRT runtime[^], and then making the API calls to show the toast:
namespace BurntToast
{
    class Program
    {
        static void Main(string[] args)
        {
            MakeToast("Ooops.", "You burnt the toast.");
        }

        /// <summary>
        /// Makes toast.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="text">The text.</param>
        private static ToastNotification MakeToast(string title, string text)
        {
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            XmlElement toastNode = toastXml.DocumentElement;
            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
            toastTextElements[0].InnerText = title;
            toastTextElements[1].InnerText = text;
            toastNode.SetAttribute("duration", "long");
            var toast = new ToastNotification(toastXml);
            var notifier = ToastNotificationManager.CreateToastNotifier();
            notifier.Show(toast);
            return toast;
        }
    }
}





此代码将编译并执行;但是当调用 CreateToastNotifier()时,你会得到一个非直观的异常:



This code will compile and execute; however when CreateToastNotifier() is invoked you will get an unintuitive exception like this:

at Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier()
at BurntToast.Program.MakeToast(String title, String text) in f:\Dropbox\Red Cell Innovation\Development\BurntToast\BurntToast\Program.cs:line 28
at BurntToast.Program.Main(String[] args) in f:\Dropbox\Red Cell Innovation\Development\BurntToast\BurntToast\Program.cs:line 11
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()





如果您在行之间阅读,问题实际上是运行时无法在Windows中找到 VisualElements 元素存储应用程序清单(因为此清单不存在)。此元素将包含所需的 ToastCapable =true属性。使其工作的唯一方法是实际使应用程序成为Windows应用商店应用。



通过一些搜索,您会发现许多模拟的第三方组件非Windows应用商店应用的Toast通知。



If you read between the lines, the problem is actually that the runtime cannot find the VisualElements element in the Windows Store application manifest (because this manifest doesn't exist). This element would contain the required ToastCapable="true" attribute. The only way to make it work is to actually make the application a Windows Store app.

With some searching you will find many third-party components that simulate toast notifications for non-Windows Store applications.


这篇关于像win8这样的吐司通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆