Introduction

So, we have moved to Windows Phone 8.1 and with this new version, the API has introduced a Notification Bar. In the early API, the major features were Toast Notification and Push Notification.
For now, in this article, we will implement a small demonstration over the Notification Bar.

Procedures

Step 1
Create a Blank Windows Phone Project with Windows Phone 8.1 API.
And add a button that will show the notification.
Step 2
Now, raise the Click event of the button and add the following code in the event handler.
<code>
  1. <code>
  2. private void simpleToast_Click(object sender, RoutedEventArgs e)
  3. {
  4. ToastTemplateType toastType = ToastTemplateType.ToastText02;
  5. XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastType);
  6. XmlNodeList toastTextElement = toastXml.GetElementsByTagName("text");
  7. toastTextElement[0].AppendChild(toastXml.CreateTextNode("Hello C# Corner"));
  8. toastTextElement[1].AppendChild(toastXml.CreateTextNode("I am poping you from a Winmdows Phone App"));
  9. IXmlNode toastNode= toastXml.SelectSingleNode("/toast");
  10. ((XmlElement)toastNode).SetAttribute("duration","long");
  11. ToastNotification toast = new ToastNotification(toastXml);
  12. ToastNotificationManager.CreateToastNotifier().Show(toast);
  13. }
  14. </code>
Before you start, ensure you have the following namespace in your project.
  1. using Windows.UI.Notifications;
  2. using Windows.Data.Xml.Dom;
Output
Note
You must have Visual Studio 2013 Update 2 at least with the Windows Phone 8.1 Emulator or any supported device to run this demo app.

Conclusion

It's a small demonstration of Toast Notification that we have implemented with the help of the Windows Phone 8.1 API.