Over a million developers have joined DZone.
Platinum Partner

Using Notifications for Non-Modal Messages--for C# and Javascript Windows 8

· Web Dev Zone

The Web Dev Zone is brought to you in partnership with Mendix.  Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.

When you want to display a message to inform your user, it is not always a good idea to use a modal MessageDialog which can be really annoying for the user.

A better way can be to use a notification in order to display a non-intrusive dialog for the user:


To do so here is the code with C#:

public static void ShowNotification(string title, string message)
    const ToastTemplateType template = Windows.UI.Notifications.ToastTemplateType.ToastText02;
    var toastXml = Windows.UI.Notifications.ToastNotificationManager.GetTemplateContent(template);

    var toastTextElements = toastXml.GetElementsByTagName("text");

    var toast = new Windows.UI.Notifications.ToastNotification(toastXml);

    var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier();


And the JavaScript version:

var showNotification = function (title, message) {
    var notifications = Windows.UI.Notifications;
    var template = notifications.ToastTemplateType.toastText02;
    var toastXml = notifications.ToastNotificationManager.getTemplateContent(template);

    var toastTextElements = toastXml.getElementsByTagName("text");

    var toast = new notifications.ToastNotification(toastXml);

    var toastNotifier = notifications.ToastNotificationManager.createToastNotifier();

And obviously do not forget to activate the toast capable feature in the Package.appxmanifest file:



The Web Dev Zone is brought to you in partnership with Mendix.  Learn more about The Essentials of Digital Innovation and how it needs to be at the heart of every organization.


Published at DZone with permission of David Catuhe , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}