public static void ShowToast(string appId, RedgateNotification notification) { XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); if (!string.IsNullOrWhiteSpace(notification.ImagePath)) { toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02); String imagePath = "file:///" + notification.ImagePath; XmlNodeList imageElements = toastXml.GetElementsByTagName("image"); imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath; } var stringElements = toastXml.GetElementsByTagName("text"); stringElements[0].AppendChild(toastXml.CreateTextNode(notification.Title)); stringElements[1].AppendChild(toastXml.CreateTextNode(notification.Message)); var toast = new ToastNotification(toastXml); var events = new ToastEvents(); toast.Activated += events.ToastActivated; toast.Dismissed += events.ToastDismissed; toast.Failed += events.ToastFailed; // Show the toast. Be sure to specify the AppUserModelId on your application's shortcut! ToastNotificationManager.CreateToastNotifier(appId).Show(toast); }
private static void ShowImageToast(string appId, string title, string message, string image) { var toastXml = ToastNotificationManager.GetTemplateContent( ToastTemplateType.ToastImageAndText02); // Fill in the text elements var stringElements = toastXml.GetElementsByTagName("text"); stringElements[0].AppendChild(toastXml.CreateTextNode(title)); stringElements[1].AppendChild(toastXml.CreateTextNode(message)); // Specify the absolute path to an image var imagePath = "file:///" + image; var imageElements = toastXml.GetElementsByTagName("image"); imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath; // Create the toast and attach event listeners var toast = new ToastNotification(toastXml); var events = new ToastEvents(); toast.Activated += events.ToastActivated; toast.Dismissed += events.ToastDismissed; toast.Failed += events.ToastFailed; // Show the toast. Be sure to specify the AppUserModelId // on your application's shortcut! ToastNotificationManager.CreateToastNotifier(appId).Show(toast); }
//Methods for displaying toasts, setting up shortcut, and toastevents. #region ToastHandlingMethods /// <summary> /// Displays a text-based Toast Message /// </summary> /// <param name="appId">string-based application ID for handling Toast messages</param> /// <param name="title">Title of the toast message to be displayed</param> /// <param name="message">Message for the toast to contain</param> static void ShowTextToast(string appId, string title, string message) { Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent( ToastTemplateType.ToastText02); // Fill in the text elements Windows.Data.Xml.Dom.XmlNodeList stringElements = toastXml.GetElementsByTagName("text"); stringElements[0].AppendChild(toastXml.CreateTextNode(title)); stringElements[1].AppendChild(toastXml.CreateTextNode(message)); // Create the toast and attach event listeners ToastNotification toast = new ToastNotification(toastXml); ToastEvents events = new ToastEvents(); //Adds details to event. toast.Activated += events.ToastActivated; toast.Dismissed += events.ToastDismissed; toast.Failed += events.ToastFailed; // Show the toast. Be sure to specify the AppUserModelId // on your application's shortcut! ToastNotificationManager.CreateToastNotifier(appId).Show(toast); }