Continuing my series based on the presentations I’m giving in Europe, today I turn to toast notifications. As with Tiles, Toast notifications are a great way to let the user know that something interesting is happening with your application.
Toast notifications can be very complex but their essence can be stripped down to just a few lines of code, especially thanks to the NotificationsExtensions library available from Microsoft.
Create a new application, add the NotificationsExtension library and add a reference to the NotificationsExtension library to the main project.
In MainPage.xaml we’ll add a single button to launch the toast,
In the event handler, in the code behind, we’ll begin by declaring a variable that implements the IToastNotificationContent interface.
We ask the NotificationsExtension library ToastContentFactory to create a ToastText01 Template Content object,
We set the text property of the Body Text Field of templateContent,
Finallly, we set the IToastNotificationContent object we declared earlier to the templateContent,
We can now call CreateNotification through the IToastNotificationContent interface, getting back a ToastNotification object,
We call CreateToastNotifier on the library’s ToastNotificationManager to get back a ToastNotifier and we use that to show our toast,
In its simplest form, that is all it takes to create a toast notification locally. We’ll take a look at using the Windows Notification Service to create toast notifications from the cloud in an upcoming blog post.
Download the project software here
Be sure to check out our new RadControls for Windows Store applications (Metro)…
Jesse Liberty has three decades of experience writing and delivering software projects. He is the author of 2 dozen books and has been a Distinguished Software Engineer for AT&T and a VP for Information Services for Citibank and a Software Architect for PBS. You can read more on his personal blog or follow him on twitter
Subscribe to be the first to get our expert-written articles and tutorials for developers!