Friday, May 3, 2013

Windows 8 Simple Toast Notifications from running app

I wanted to add a very basic toast notification for an actively running windows 8 app to indicate that a long running process has been completed. At the most basic level I needed to build up some XML and use it to create a ToastNotification that is shown via the ToastNotifier. E.g.

    using Windows.UI.Notifications;

    //...

    Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
    toastDOM.LoadXml(@"
  
    
      Body text that wraps over three lines
    
  
");

    ToastNotification toast = new ToastNotification(toastDOM);

    ToastNotifier tn = ToastNotificationManager.CreateToastNotifier();
    tn.Show(toast);

However, when run, the ToastNotifier has the Setting value "DisabledByManifest". So somewhere in the Package.appxmanifest I need to enable toast notifications. Apparently it is "in the Notifications section of the Application UI tab" (Source).

I couldn't see it initially. After a bit of hunting I found it under "All Image Assets".