Scheduling Toast Notifications

You can schedule a toast to appear any time in the future—you supply a time
at which you want the toast notification to appear, and it shows up on demand.
Your application doesn’t even have to be running! In order to better manage
your toasts, however, you should set the Id property of the toast to a string of
up to 16 characters. Having an ID allows you to refer to the toast (and possibly
cancel it).

Note that all the previous examples have used a ToastNotifier instance, but
haven’t stored a reference to it for later use. The ToastNotifier class provides
several useful methods, and if you plan to work with toast notifications after
they’re created, you will need to create a specific reference to a ToastNotifier
instance to work with. Specifically, the ToastNotifier class provides these
members:

  • AddToSchedule, RemoveFromSchedule
  • Show (which you previously called), Hide
  • GetScheduledToastNotifications

To create a scheduled notification, start by creating an instance of the
ScheduledToastNotification class. To its constructor, pass the XML content of
a ToastContent instance—you can use the GetXml method to retrieve the
XML content. Next, create the ToastNotifier instance, and call its
AddToSchedule method, supplying the ScheduledToastNotification instance as
a parameter. In addition, supply the time at which you want to display the
notification.

NOTE

You cannot schedule more than 4096 notifications. Also note that
you cannot schedule a notification in the past (in other words, you
can’t break the inviolable laws of the space-time continuum).

Creating a Recurring Notification
To create a recurring notification, follow the exact same steps as for a
scheduled notification, except that you must also specify the snooze interval
(that is, how long to wait before reattempting the notification), which can be a
value between 60 seconds and 60 minutes. Also, specify the maximum occurrences
of the notification (a value between 1 and 5).

TIP: Specify an Id property when creating scheduled and/or recurring toast
notifications. Doing so will make it easier to identify notifications when
reviewing or cancelling them.

ldn-expertkgetz

This post is an excerpt from the online courseware for ourWindows 8 Using XAML: Views, Resources, and Toastscourse written by expert Ken Getz.

Ken Getz is a Visual Studio expert with over 25 years of experience as a successful developer and consultant. He is a nationally recognized author and speaker, as well as a featured instructor for LearnNowOnline.

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *