WP8.1StoreApp(WP8.1RT)---本地Toast

Posted by baicai on April 17, 2014

WP7/8中的Toast是不能在前台弹出的。

WP8.1StoreApp可以利用Win8中的方式: 

private void Toast(string title,string content)
{
    ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;//WindowsPhone上只支持这一种
    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
    XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
    toastTextElements[0].AppendChild(toastXml.CreateTextNode(title));
    toastTextElements[1].AppendChild(toastXml.CreateTextNode(content));
    ToastNotification toast = new ToastNotification(toastXml);
    var guid = Guid.NewGuid().ToString("N").Substring(0, 16);
    toast.Tag = guid;
    toast.Dismissed += (sender, args) => ToastNotificationManager.History.Remove(guid);
    toast.Activated += (sender, args) => ToastNotificationManager.History.Remove(guid);
    ToastNotificationManager.CreateToastNotifier().Show(toast);
}