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>- <code>
- private void simpleToast_Click(object sender, RoutedEventArgs e)
- {
- ToastTemplateType toastType = ToastTemplateType.ToastText02;
-
- XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastType);
-
- XmlNodeList toastTextElement = toastXml.GetElementsByTagName("text");
- toastTextElement[0].AppendChild(toastXml.CreateTextNode("Hello C# Corner"));
- toastTextElement[1].AppendChild(toastXml.CreateTextNode("I am poping you from a Winmdows Phone App"));
-
- IXmlNode toastNode= toastXml.SelectSingleNode("/toast");
- ((XmlElement)toastNode).SetAttribute("duration","long");
-
- ToastNotification toast = new ToastNotification(toastXml);
- ToastNotificationManager.CreateToastNotifier().Show(toast);
-
-
- }
- </code>
Before you start, ensure you have the following namespace in your project.
- using Windows.UI.Notifications;
- 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.