Toast Notifications
Visual Basic tutorials for UWP apps.
6 posts
Page 1 of 1
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;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Is this for Windows 8 only? Because I remember using completely different coding in my softwares.
Yes its for W8...it is posted in the W8 section lol
This is all metro code like the others ive been posting which will hopefully help people with the basics when they move to metro programming and im still learning myself but my brain is having a hard time with all this new stuff and xaml gives me a headache :lol:
This is all metro code like the others ive been posting which will hopefully help people with the basics when they move to metro programming and im still learning myself but my brain is having a hard time with all this new stuff and xaml gives me a headache :lol:
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
just now and from this post only i heard XAML
thanks codenstuff , i will be trying to learn xaml now

thanks codenstuff , i will be trying to learn xaml now


Find my programs on Softpedia
CodenStuff wrote:Yes its for W8...it is posted in the W8 section lolActually, I only saw the 'Visual Basic' at the end and got confused. I didn't read the whole directory.
This is all metro code like the others ive been posting which will hopefully help people with the basics when they move to metro programming and im still learning myself but my brain is having a hard time with all this new stuff and xaml gives me a headache :lol:
6 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023