如何在 UWP 应用中创建信息丰富的 Toast 通知 [英] How to create informative toast notification in UWP App

查看:24
本文介绍了如何在 UWP 应用中创建信息丰富的 Toast 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想在执行特定操作时通知用户,例如成功更新记录或添加新记录,但没有内置控件可以显示此类信息.有没有类似 Android Toast.makeText for UWP 的东西?

In my app, I want to inform user when particular action had performed, like record updated successfully or new record added, but there's not inbuilt control to that can display such information. Is there anything similar to Android Toast.makeText for UWP?

推荐答案

是的,UWP 有 Toast 通知 :)

Yes, UWP has Toast Notifications :)

这是显示简单通知的示例代码:

Here is sample code to display simple notification:

private void ShowToastNotification(string title, string stringContent)
{
        ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier();
        Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
        Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text");
        toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(title));
        toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(stringContent));
        Windows.Data.Xml.Dom.IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
        Windows.Data.Xml.Dom.XmlElement audio = toastXml.CreateElement("audio");
        audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS");

        ToastNotification toast = new ToastNotification(toastXml);
        toast.ExpirationTime = DateTime.Now.AddSeconds(4);
        ToastNotifier.Show(toast);
}

在本文中,您可以找到如何自定义它:

In this article you can find how to customize it:

https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-adaptive-interactive-toasts

这篇关于如何在 UWP 应用中创建信息丰富的 Toast 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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