如何在Windows Phone 8.1中阅读Toast Notification属性?

时间:2014-09-24 13:48:58

标签: windows xaml windows-phone-8 windows-phone-8.1

我创建了以下Toast通知

ToastTemplateType toastType = ToastTemplateType.ToastText02;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastType);
XmlNodeList toastTextElement = toastXml.GetElementsByTagName("text");
toastTextElement[0].AppendChild(toastXml.CreateTextNode("Hello C# Corner"));
toastTextElement[1].AppendChild(toastXml.CreateTextNode("I am poping you from a Winmdows Phone App"));
IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("duration", "long");
((XmlElement)toastNode).SetAttribute("type", "Employee");
((XmlElement)toastNode).SetAttribute("launch", "<cat state='angry'><facebite state='true' /></cat>");
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);

我想知道如何访问类型属性。

当我尝试使用下面的代码时,它返回null

var att = toast.Content.Attributes;

2 个答案:

答案 0 :(得分:1)

调试显示答案。

 var att = toast.Content.ChildNodes[0].Attributes[1].NodeValue;

答案 1 :(得分:0)

var att = 
toast.Content
.SelectSingleNode("/toast/visual/binding")
.SelectNodes("text")[0].InnerText