Last active
December 23, 2015 16:39
-
-
Save adamsteinert/6663368 to your computer and use it in GitHub Desktop.
Simple text toast notification for windows store apps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Toast Types: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.toasttemplatetype.aspx | |
// Enable in appxmanifest! | |
// Toasts won't show in simulator. | |
// More info: http://www.jeffblankenburg.com/2012/11/10/31-days-of-windows-8-day-10-toast-notifications | |
public class Toaster | |
{ | |
public static void SendTextToast(string text) | |
{ | |
var template = ToastTemplateType.ToastText01; | |
var doc = ToastNotificationManager.GetTemplateContent(template); | |
XmlNodeList toastTextElements = doc.GetElementsByTagName("text"); | |
toastTextElements[0].AppendChild(doc.CreateTextNode(text)); | |
//This is the options code, which is all optional based on your needs. | |
//IXmlNode toastNode = doc.SelectSingleNode("/toast"); | |
//((XmlElement)toastNode).SetAttribute("duration", "long"); | |
//XmlElement audioNode = doc.CreateElement("audio"); | |
//audioNode.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Alarm"); | |
////Must be used when looping audio has been selected. | |
//audioNode.SetAttribute("loop", "true"); | |
//toastNode.AppendChild(audioNode); | |
var toast = new ToastNotification(doc); | |
ToastNotificationManager.CreateToastNotifier().Show(toast); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment