Skip to content

Instantly share code, notes, and snippets.

@boyofgreen
Last active March 11, 2016 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save boyofgreen/ce96cef1b403701e8606 to your computer and use it in GitHub Desktop.
Save boyofgreen/ce96cef1b403701e8606 to your computer and use it in GitHub Desktop.
notification inside a Windows 10 app
if (typeof Windows !== 'undefined'&& typeof Windows.UI !== 'undefined' && typeof Windows.UI.Notifications !== 'undefined') {
// Construct the toast notification content
var toastContent = new Windows.Data.Xml.Dom.XmlDocument();
var toast = toastContent.createElement("toast");
toastContent.appendChild(toast);
var visual = toastContent.createElement("visual");
toast.appendChild(visual);
var binding = toastContent.createElement("binding");
binding.setAttribute("template", "ToastGeneric");
visual.appendChild(binding);
// Title text
var text = toastContent.createElement("text");
text.innerText = "This is the message for my toast";
binding.appendChild(text);
// TODO: Add up to two more text elements
// Override the app logo
var appLogo = toastContent.createElement("image");
appLogo.setAttribute("placement", "appLogoOverride");
appLogo.setAttribute("src", "https://unsplash.it/150/150/?random");
appLogo.setAttribute("alt", "random graphic");
binding.appendChild(appLogo);
// And send the toast notification
var notifications = Windows.UI.Notifications;
var toast = new notifications.ToastNotification(toastContent);
notifications.ToastNotificationManager.createToastNotifier().show(toast);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment