Search code examples
windowsxamlwindows-phone-8windows-phone-8.1

How to read Toast Notification attributes in Windows Phone 8.1?


I have created below toast notification

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

I want to know how to access the type attribute.

When I tried with below code it's returning null

var att = toast.Content.Attributes;

Solution

  • Debugging shows you the answer.

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