【问题标题】:How to read Toast Notification attributes in Windows Phone 8.1?如何在 Windows Phone 8.1 中读取 Toast 通知属性?
【发布时间】:2014-09-24 13:48:57
【问题描述】:

我在下面创建了 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);

我想知道如何访问 type 属性。

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

var att = toast.Content.Attributes;

【问题讨论】:

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


    【解决方案1】:

    调试告诉你答案。

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

    【讨论】:

      【解决方案2】:
      var att = 
      toast.Content
      .SelectSingleNode("/toast/visual/binding")
      .SelectNodes("text")[0].InnerText
      

      【讨论】:

        猜你喜欢
        • 2017-08-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多