Windows 8 Toast Notifications

What is Toast Notifications?

Windows 8 has a notification system similar to that implemented in mobile operation systems such as Windows Phone, IOS and Android.

A Windows 8 Toast is a notification triggered by an application or the operating system itself that is displayed to the user by way of a small pop-up notification.

A toast is a small, informational window displayed by certain kinds of software, especially instant messaging clients such as Skype and Windows Live Messenger. Toasts notify users of various kinds of events, such as reception of new e-mail, a change in a peer’s availability, or a change in network connectivity.

Toast Templates

Untitled

Demo

Let’s create project and name it “ToastNotificationsDemo”

x

Then open MainPage.xaml from solution explorer

x

Then drag button from toolbox to page designer and give it content “Show Toast” from properties window

x

Then we need to add event handler to button to show toast lets add click event from properties windows as you see and named it “ShowToastClickEvent”

x

Now event created for you in “MainPage.xaml.cs”

Let’s add Microsoft notification extensions from NuGet Packages (you can read more about it from here http://msdn.microsoft.com/en-us/library/windows/apps/hh969156.aspx)

open package manager console Then install notification package using this command

PM> Install-Package NotificationsExtensions.WinRT

x

Now you will find NotificationsExtensions.WinRT referenced in your project

Let’s back to code “MainPage.xaml.cs” and add our name spaces we will use

using NotificationsExtensions.ToastContent;

using Windows.UI.Notifications; 

Then add event body

privatevoid ShowToastClickEvent(object sender, RoutedEventArgs e)

        {

            IToastText02 content = ToastContentFactory.CreateToastText02();

            content.TextBodyWrap.Text = “Hello…Body…”;

            content.TextHeading.Text = “Hello…Header”;

            ToastNotification notification = content.CreateNotification();

            ToastNotificationManager.CreateToastNotifier().Show(notification);

        }

Finally we let’s create notification 

 

            ToastNotification notification = content.CreateNotification();

Then till the notification manager we need to display it now

            ToastNotificationManager.CreateToastNotifier().Show(notification);

Wait don’t Run Now……

We must enable toast capability from Package.appxmanifest file

x

Now It’s time to run the app and the result will come like that …

Untitled

There is more about notifications if you need learn more go to http://msdn.microsoft.com/en-us/library/windows/apps/hh868266.aspx

cropped-windows1.png

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s