Toast Notifications
Posted: Tue May 08, 2012 3:13 am
How to show toast notifications
A toast notification is basically a popup that appears in the top-right corner of the screen to inform the user of activity within your app. An email app for example would use these notifications to let the user know they have a new email or an IM app could use it to let you know when someone logs on or sends you a message.
You can use 4 different types of toast notifications with or without an image and below you will find the basic codes on how to use them all.
ToastText01
Displays a single string wrapped across 3 lines.
Display first string in bold and a second in regular wrapped across 2 lines.
Display first string in bold wrapped across 2 lines and a second in regular on the third line.
Display first string in bold a second string in regular and a third string in regular.
ToastImageAndText01
Image with single string wrapped across 3 lines.
Image with first string in bold and second regular wrapped across 2 lines.
Image with first string in bold across 2 lines and second string regular on third line.
Image with first string in bold a second string in regular and a third string in regular.
You need to change the "Toast Capable" setting in your app package settings to 'Yes' in order to use toast within your app.
Hope they come in handy cooll;
A toast notification is basically a popup that appears in the top-right corner of the screen to inform the user of activity within your app. An email app for example would use these notifications to let the user know they have a new email or an IM app could use it to let you know when someone logs on or sends you a message.
You can use 4 different types of toast notifications with or without an image and below you will find the basic codes on how to use them all.

ToastText01
Displays a single string wrapped across 3 lines.
Code: Select all
ToastText02Dim ToastXML As XmlDocument = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01)
ToastXML.GetElementsByTagName("text").First().AppendChild(ToastXML.CreateTextNode("Single line of text wrapped across 3 lines inside the popup notification."))
ToastNotificationManager.CreateToastNotifier().Show(New ToastNotification(ToastXML))
Display first string in bold and a second in regular wrapped across 2 lines.
Code: Select all
ToastText03Dim ToastXML As XmlDocument = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02)
ToastXML.GetElementsByTagName("text").First().AppendChild(ToastXML.CreateTextNode("Toast Title"))
ToastXML.GetElementsByTagName("text").ElementAt(1).AppendChild(ToastXML.CreateTextNode("Single line of text wrapped across 2 lines inside the notification popup."))
ToastNotificationManager.CreateToastNotifier().Show(New ToastNotification(ToastXML))
Display first string in bold wrapped across 2 lines and a second in regular on the third line.
Code: Select all
ToastText04Dim ToastXML As XmlDocument = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText03)
ToastXML.GetElementsByTagName("text").First().AppendChild(ToastXML.CreateTextNode("Toast Title wrapped across 2 lines in the notification"))
ToastXML.GetElementsByTagName("text").ElementAt(1).AppendChild(ToastXML.CreateTextNode("Single line of text"))
ToastNotificationManager.CreateToastNotifier().Show(New ToastNotification(ToastXML))
Display first string in bold a second string in regular and a third string in regular.
Code: Select all
Dim ToastXML As XmlDocument = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText04)
ToastXML.GetElementsByTagName("text").First().AppendChild(ToastXML.CreateTextNode("Toast Title"))
ToastXML.GetElementsByTagName("text").ElementAt(1).AppendChild(ToastXML.CreateTextNode("First line of text"))
ToastXML.GetElementsByTagName("text").ElementAt(2).AppendChild(ToastXML.CreateTextNode("Second line of text"))
ToastNotificationManager.CreateToastNotifier().Show(New ToastNotification(ToastXML))
ToastImageAndText01
Image with single string wrapped across 3 lines.
Code: Select all
ToastImageAndText02Dim ToastXML As XmlDocument = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01)
ToastXML.GetElementsByTagName("text").First().AppendChild(ToastXML.CreateTextNode("Single line of text wrapped across 3 lines inside the popup notification."))
Dim imageElements As XmlNodeList = ToastXML.GetElementsByTagName("image")
DirectCast(imageElements.ElementAt(0), XmlElement).SetAttribute("src", "ms-resource:images/class_scoutred.png")
ToastNotificationManager.CreateToastNotifier().Show(New ToastNotification(ToastXML))
Image with first string in bold and second regular wrapped across 2 lines.
Code: Select all
ToastImageAndText03Dim ToastXML As XmlDocument = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02)
ToastXML.GetElementsByTagName("text").First().AppendChild(ToastXML.CreateTextNode("Toast Title"))
ToastXML.GetElementsByTagName("text").ElementAt(1).AppendChild(ToastXML.CreateTextNode("Single line of text wrapped across 2 lines inside the notification popup."))
Dim imageElements As XmlNodeList = ToastXML.GetElementsByTagName("image")
DirectCast(imageElements.ElementAt(0), XmlElement).SetAttribute("src", "ms-resource:images/class_scoutred.png")
ToastNotificationManager.CreateToastNotifier().Show(New ToastNotification(ToastXML))
Image with first string in bold across 2 lines and second string regular on third line.
Code: Select all
ToastImageAndText04Dim ToastXML As XmlDocument = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText03)
ToastXML.GetElementsByTagName("text").First().AppendChild(ToastXML.CreateTextNode("Toast Title wrapped across 2 lines in the notification"))
ToastXML.GetElementsByTagName("text").ElementAt(1).AppendChild(ToastXML.CreateTextNode("Single line of text"))
Dim imageElements As XmlNodeList = ToastXML.GetElementsByTagName("image")
DirectCast(imageElements.ElementAt(0), XmlElement).SetAttribute("src", "ms-resource:images/class_scoutred.png")
ToastNotificationManager.CreateToastNotifier().Show(New ToastNotification(ToastXML))
Image with first string in bold a second string in regular and a third string in regular.
Code: Select all
In the ToastImageAndText notifications you will want to replace "ms-resource:images/class_scoutred.png" with your own image resource/url you wish to display with your toast notification.Dim ToastXML As XmlDocument = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04)
ToastXML.GetElementsByTagName("text").First().AppendChild(ToastXML.CreateTextNode("Toast Title"))
ToastXML.GetElementsByTagName("text").ElementAt(1).AppendChild(ToastXML.CreateTextNode("First line of text"))
ToastXML.GetElementsByTagName("text").ElementAt(2).AppendChild(ToastXML.CreateTextNode("Second line of text"))
Dim imageElements As XmlNodeList = ToastXML.GetElementsByTagName("image")
DirectCast(imageElements.ElementAt(0), XmlElement).SetAttribute("src", "ms-resource:images/class_scoutred.png")
ToastNotificationManager.CreateToastNotifier().Show(New ToastNotification(ToastXML))
You need to change the "Toast Capable" setting in your app package settings to 'Yes' in order to use toast within your app.
Hope they come in handy cooll;