c# - 如何在 UWP App 中创建信息提示通知

标签 c# windows-runtime uwp windows-10-universal

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

最佳答案

是的,UWP 有 Toast 通知:)

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

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

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

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

关于c# - 如何在 UWP App 中创建信息提示通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37541923/

相关文章:

c# - 断点在 Visual Studio 2017 中的 xamarin uwp 中不起作用

windows - 如何在 UWP 上的 Xamarin.Forms WebView 中启用 WebGL?

C#:即使在使用 httpclient 发送 CSRF token 后仍获得 403

javascript - 适用于Electron JS的WinRT API “Windows.UI.ViewManagement”?

microsoft-metro - linq to sql(Windows Phone 的本地数据库)更好吗? (或者)移动版的 sqlite-net 版本更好?用于 Windows Phone 8 本地数据库创建

c# - ControlTemplate DataTrigger 未在 ItemsControl ControlTemplate 中触发

C# 反序列化 - 捕获 TargetInitationException 是否安全?

c# - skydrive System.Dynamic.DynamicObject

c# - 有什么方法可以阻止 WPF Popup 在离开屏幕时重新定位自身?

c# - String.Substring() 似乎是这段代码的瓶颈