Unlike Windows 8, Windows Phone only has one template for toast notification i.e. “toastText02”. It has application icon on left and accepts two text string with first with bold text and another with normal text. It is advisable to have very short strings to avoid truncation. We can use XML functions to set above two text.
When user clicks on toast notification, the app gets launched. We can set launch attribute of toast element containing parameters which we can use to decide navigation page when the app is launched. We can write following code to set launch parameter.
So if our launch page is MainPage.xaml then uri would be “MainPage.xaml?FileID=1”. We can read the QueryString value in MainPage.xaml and do operation as per project requirement.
Now we can create a ScheduledToastNotification where we can pass XmlDocument object containing information about toast and scheduled time when the toast notification should be displayed. We can optional also set “ID” property for ScheduledToastNotification so that we can cancel it in future if required.
We can also set MaximumSnoozeCount parameter to set maximum number of times notification should be displayed and SnoozeInterval parameter to set time interval between notifications. SnoozeInterval should be between 1 to 60 minutes and MaximumSnoozeCount should be between 1 to 5.
If we don’t want to show ToastNotification popup and only show the details in action center then we can set SuppressPopup property.
It is advisable to check if any toast notification with similar ID is already created or not. If already created then you can notify the user or delete it.
Now we can create ToastNotifier object and add scheduled notification using following code
For ToastNotification to work correctly we have to set Notification Service as “WNS” in WMAppManifest.xml file. This is one of the most important steps as your app could be reject in Certification process if “WNS” is not selected in Notification Service.
Below is complete code to create ScheduledToastNotification in Windows Phone Silverlight 8.1 app.