public void showToast(ToastTemplateType type) { var xmlDoc = ToastHelper.CreateToast(this, type); var notification = new ToastNotification(xmlDoc); _toastNotifier.Show(notification); }
private static void Main(string[] args) { const string title = "SchoolTime by Romeo Salayo"; const string msg = "This application has been blocked during school hours, please try again later."; const ToastTemplateType template = ToastTemplateType.ToastText02; var toastXml = ToastNotificationManager.GetTemplateContent(template); var toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(title)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(msg)); ToastNotificationManager .CreateToastNotifier("SchoolTime") .Show(new ToastNotification(toastXml)); var sb = new StringBuilder(); sb.AppendLine(@" _________ .__ ._____________.__ "); sb.AppendLine(@" / _____/ ____ | |__ ____ ____ | \__ ___/|__| _____ ____ "); sb.AppendLine(@" \_____ \_/ ___\| | \ / _ \ / _ \| | | | | |/ \_/ __ \ "); sb.AppendLine(@" / \ \___| Y ( <_> | <_> ) |_| | | | Y Y \ ___/ "); sb.AppendLine(@"/_______ /\___ >___| /\____/ \____/|____/____| |__|__|_| /\___ >"); sb.AppendLine(@" \/ \/ \/ \/ \/ "); sb.AppendLine(@" By Romeo Salayo"); Console.Title = title; Console.WriteLine(sb.ToString()); Console.WriteLine(); Console.WriteLine(msg); Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
/* * <toast> * <visual> * <binding template="ToastText02"> * <text id="1">Espresso</text> * <text id="2"> Lorem ipsum dolor sit amet, consectetur elit.</text> * </binding> * </visual> * </toast> */ private void SimpleTextOldSchool() { ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); SendOldSchoolToast(toastXml, LocalizableStrings.TOAST_SIMPLE_TEXT); }
private static Windows.Data.Xml.Dom.XmlDocument CreateToastNotificationXml(ToastTemplateType toastTemplateType, string[] text, string image) { var toastXml = ToastNotificationManager.GetTemplateContent((Windows.UI.Notifications.ToastTemplateType)toastTemplateType); var textNodes = toastXml.GetElementsByTagName("text"); if (textNodes.Length != text.Length) { throw new ArgumentException("more text fields than supported by the template"); } for (int i = 0; i < textNodes.Length; i++) { textNodes[i].InnerText = text[i]; } // for a text only template, images will not be supplied. if (!string.IsNullOrEmpty(image)) { var imageNodes = toastXml.GetElementsByTagName("image"); if (imageNodes.Length != 1) { throw new ArgumentException("invalid number of images"); } imageNodes[0].Attributes.GetNamedItem("src").NodeValue = image; } return(toastXml); }
public static void SendToast( string head, string text, DateTimeOffset dueTime, string launch) { ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(head)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(text)); IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); XmlElement audio = toastXml.CreateElement("audio"); audio.SetAttribute("src", "ms-winsoundevent:Notification.IM"); toastNode.AppendChild(audio); if (launch != null) { ((XmlElement)toastNode).SetAttribute("launch", launch); } ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime); scheduledToast.Id = "Future_Toast"; ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast); }
private void ToastNotificationOptions_Click(object sender, RoutedEventArgs e) { ToastTemplateType toastType = ToastTemplateType.ToastImageAndText02; XmlDocument toastXML = ToastNotificationManager.GetTemplateContent(toastType); XmlNodeList toastText = toastXML.GetElementsByTagName("text"); XmlNodeList toastImages = toastXML.GetElementsByTagName("image"); toastText[0].InnerText = "Funny cat"; toastText[1].InnerText = "This cat looks like it's trying to eat your face."; ((XmlElement)toastImages[0]).SetAttribute("src", "ms-appx:///Assets/10-XAML-CatImageSmall.png"); ((XmlElement)toastImages[0]).SetAttribute("alt", "Scary Cat Face"); //This is the options code, which is all optional based on your needs. IXmlNode toastNode = toastXML.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "long"); XmlElement audioNode = toastXML.CreateElement("audio"); audioNode.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Alarm"); //Must be used when looping audio has been selected. audioNode.SetAttribute("loop", "true"); toastNode.AppendChild(audioNode); //You can append any text data you would like to the optional //launch property, but clicking a Toast message should drive //the user to something contextually relevant. ((XmlElement)toastNode).SetAttribute("launch", "<cat state='angry'><facebite state='true' /></cat>"); ToastNotification toast = new ToastNotification(toastXML); ToastNotificationManager.CreateToastNotifier().Show(toast); }
private void showInfoMessage(string title, string content) { var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; localSettings.Values["ToastMessageTitle"] = title; localSettings.Values["ToastMessageContent"] = content; // Get Template ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; // Put text in the template XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(title)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(content)); // Set the Duration IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "long"); // Show custom Text var toastNavigationUriString = "ShowInfoMessage"; XmlElement toastElement = ((XmlElement)toastXml.SelectSingleNode("/toast")); toastElement.SetAttribute("launch", toastNavigationUriString); // Create Toast and show ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
public static void Toast(string msg) { //1. create element ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); //2.设置消息文本 XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(msg)); //3. 图标 Windows.Data.Xml.Dom.XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImageAttributes[0]).SetAttribute("src", $"ms-appx:///Assets/StoreLogo.png"); ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "logo"); // 4. duration IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "short"); // 5. audio XmlElement audio = toastXml.CreateElement("audio"); audio.SetAttribute("src", $"ms-winsoundevent:Notification.SMS"); toastNode.AppendChild(audio); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
private async void OnReminderButtonClicked(object sender, RoutedEventArgs e) { ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); if (notifier.Setting != NotificationSetting.Enabled) { var dialog = new MessageDialog("Notifications are currently disabled"); await dialog.ShowAsync(); return; } ToastTemplateType toastTemplate = ToastTemplateType.ToastText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode("Reminder! Check Friends With Paws")); var date = DateTimeOffset.Now.AddSeconds(15); var stnA = new ScheduledToastNotification(toastXml, date); notifier.AddToSchedule(stnA); ToastTemplateType toastTemplateB = ToastTemplateType.ToastText01; XmlDocument toastXmlB = ToastNotificationManager.GetTemplateContent(toastTemplateB); XmlNodeList toastTextElementsB = toastXmlB.GetElementsByTagName("text"); toastTextElementsB[0].AppendChild(toastXmlB.CreateTextNode("Please check what's new with Friends With Paws")); var dateB = DateTimeOffset.Now.AddSeconds(60); IXmlNode toastNodeB = toastXmlB.SelectSingleNode("/toast"); ((XmlElement)toastNodeB).SetAttribute("duration", "long"); var stnB = new ScheduledToastNotification(toastXmlB, dateB); notifier.AddToSchedule(stnB); }
public void Run(IBackgroundTaskInstance taskInstance) { // simple example with a Toast, to enable this go to manifest file // and mark App as TastCapable - it won't work without this // The Task will start but there will be no Toast. guid = GetGuid(); var Reports = GeofenceMonitor.Current.ReadReports(); var SelectedReport = Reports.FirstOrDefault(report => (report.Geofence.Id == "My Home Geofence"));// && (report.NewState == GeofenceState.Entered || report.NewState == GeofenceState.Exited)); x = SelectedReport.Geoposition.Coordinate.Latitude; //x = GeofenceMonitor.Current.LastKnownGeoposition.Coordinate.Longitude; //await GetCoordinates(); //Geolocator geolocator = new Geolocator(); //CancellationTokenSource CancellationTokenSrc = new CancellationTokenSource(); //CancellationToken token = CancellationTokenSrc.Token; //var position = await geolocator.GetGeopositionAsync(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(30)).AsTask(token); //x = position.Coordinate.Longitude; ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList textElements = toastXml.GetElementsByTagName("text"); textElements[0].AppendChild(toastXml.CreateTextNode(y.ToString())); textElements[1].AppendChild(toastXml.CreateTextNode("exit " + x.ToString() + " I'm wergwerg message from your background task!")); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastXml)); }
public ToastText(string message, ToastTemplateType type) { xmlDoc = ToastNotificationManager.GetTemplateContent(type); var textTag = xmlDoc.GetElementsByTagName("text").First(); textTag.AppendChild(xmlDoc.CreateTextNode(message)); }
public void Run(IBackgroundTaskInstance taskInstance) { var storage = Windows.Storage.ApplicationData.Current.LocalSettings; if (!storage.Containers.ContainsKey("key")) { storage.CreateContainer("key", Windows.Storage.ApplicationDataCreateDisposition.Always); } string str = storage.Values["key"] as string; BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(str)); toastTextElements[1].AppendChild(toastXml.CreateTextNode("Toast Description")); ToastNotification toast = new ToastNotification(toastXml); toast.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(30); toast.Failed += toast_Failed; ToastNotificationManager.CreateToastNotifier().Show(toast); deferral.Complete(); return; }
private void SendToast() { try { ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///Assets/SecondaryTiles/espresso.jpg"); ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", SharedStrings.TOAST_TEXT_TITLE); IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("launch", SharedStrings.TOAST_PARAMETER_PREFIX + SharedStrings.TOAST_PARAMETER_STRING); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(SharedStrings.TOAST_TEXT_TITLE)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(SharedStrings.TOAST_TEXT_BODY)); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
public void Show(string message) { ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(message)); XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///Assets/Logo.scale-240.png"); ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "logo"); IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "short"); var toastNavigationUriString = "#/MainPage.xaml?param1=12345"; var toastElement = ((XmlElement)toastXml.SelectSingleNode("/toast")); toastElement.SetAttribute("launch", toastNavigationUriString); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
//Ref: https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.toasttemplatetype //Templates Ref: https://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx internal static XmlDocument CreateToast(Toast toast, ToastTemplateType type) { XmlDocument toastXML = ToastNotificationManager.GetTemplateContent(type); XmlNodeList toastTexts = toastXML.GetElementsByTagName("text"); if (type == ToastTemplateType.ToastText01 || type == ToastTemplateType.ToastImageAndText01) { toastTexts[0].AppendChild(toastXML.CreateTextNode(toast.HeadlineText)); } else if (type == ToastTemplateType.ToastText02 || type == ToastTemplateType.ToastImageAndText02 || type == ToastTemplateType.ToastText03 || type == ToastTemplateType.ToastImageAndText03) { toastTexts[0].AppendChild(toastXML.CreateTextNode(toast.HeadlineText)); toastTexts[1].AppendChild(toastXML.CreateTextNode(toast.BodyText1)); } else { toastTexts[0].AppendChild(toastXML.CreateTextNode(toast.HeadlineText)); toastTexts[1].AppendChild(toastXML.CreateTextNode(toast.BodyText1)); toastTexts[2].AppendChild(toastXML.CreateTextNode(toast.BodyText2)); } if (type.ToString().Contains("Image")) { XmlNodeList toastImg = toastXML.GetElementsByTagName("image"); XmlElement img = (XmlElement)toastImg[0]; img.SetAttribute("src", toast.Image); img.SetAttribute("alt", toast.ImgAlt); } return(toastXML); }
public void Run(IBackgroundTaskInstance taskInstance) { // 受信したRaw Notification RawNotification notification = (RawNotification)taskInstance.TriggerDetails; // トーストのテンプレートを選択 ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); // トーストに表示するテキストを指定 XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode("What's New")); // トーストに表示する画像を指定 XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "https://2.bp.blogspot.com/-Euo8ySieZ1s/VlAYy90a2oI/AAAAAAAA02Y/r3AmTznIjOo/s800/allergy_kuri.png"); // トーストをクリックした場合、パラメータ付きでアプリを起動する IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("launch", notification.Content); // トースト表示 ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
public static void ToastImageAndText04(string t1, string t2, string t3, string imgsrc, string imgalt = "") { ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText04; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(t1)); if (t2 != null) { toastTextElements[1].AppendChild(toastXml.CreateTextNode(t2)); } if (t3 != null) { toastTextElements[2].AppendChild(toastXml.CreateTextNode(t3)); } if (!string.IsNullOrEmpty(imgsrc)) { XmlNodeList toastImgElement = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImgElement[0]).SetAttribute("src", imgsrc); ((XmlElement)toastImgElement[0]).SetAttribute("alt", imgalt); } IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); XmlElement audio = toastXml.CreateElement("audio"); audio.SetAttribute("silent", "true"); toastNode?.AppendChild(audio); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
private void ShowToastNotification(String message) { ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); // Set Text XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(message)); // toast duration IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "short"); // toast navigation var toastNavigationUriString = "#/MainPage.xaml?param1=12345"; var toastElement = ((XmlElement)toastXml.SelectSingleNode("/toast")); toastElement.SetAttribute("launch", toastNavigationUriString); // Create the toast notification based on the XML content you've specified. ToastNotification toast = new ToastNotification(toastXml); // Send your toast notification. ToastNotificationManager.CreateToastNotifier().Show(toast); }
public static void Toast_Notification_For_Devs(string title, string subtitle) { try { ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(title)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(subtitle)); IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("launch", "MainPage.xaml"); XmlElement audio = toastXml.CreateElement("audio"); audio.SetAttribute("src", Memory.Toast_Sound); toastNode.AppendChild(audio); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastXml)); System.Diagnostics.Debug.WriteLine("Toast notification for devs created " + "(" + title + " / " + subtitle + ")"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Greška pri registraciji \"Toast notification for devs\" za " + title + " (" + ex.Message + ")"); } }
public static ToastNotification DownloadToast(string filename, DownloadResult result) { ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); switch (result) { case DownloadResult.Success: toastTextElements[0].AppendChild(toastXml.CreateTextNode("下载完成!")); toastTextElements[1].AppendChild(toastXml.CreateTextNode("文件:" + filename + "下载完成")); break; case DownloadResult.Failure: toastTextElements[0].AppendChild(toastXml.CreateTextNode("下载失败!")); toastTextElements[1].AppendChild(toastXml.CreateTextNode("文件:" + filename + "下载失败")); break; default: break; } var doc = new Windows.Data.Xml.Dom.XmlDocument(); ToastNotification toast = new ToastNotification(toastXml); return(toast); }
private void SendToastMessageToUser(string header, string body) { const ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; var toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); var toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(header)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(body)); var toastNode = toastXml.SelectSingleNode("/toast"); var xmlElement = (XmlElement)toastNode; if (xmlElement != null) { xmlElement.SetAttribute("duration", "long"); } var toast = new ToastNotification(toastXml) { ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(3600) }; ToastNotificationManager.CreateToastNotifier().Show(toast); }
private async void SaveAsync(object sender, Windows.UI.Xaml.RoutedEventArgs e) { if (Validate()) { Gebruiker gebruiker = new Gebruiker(Gebruikersnaam.Text, Password.Password.ToString(), Soort.SelectedItem.ToString()); var answer = await gebruikerViewModel.Register(gebruiker); if (answer == "error") { usernameError.Text = "Gebruikersnaam in gebruik"; usernameError.Visibility = Visibility.Visible; } else { string[] tokens = answer.Split('"'); var token = tokens[4]; Gebruiker user = new Gebruiker(Int32.Parse(tokens[21].ToString()), tokens[13].ToString(), tokens[17].ToString()); ((App)Application.Current).gebruiker = user; GlobalToken.Token = tokens[3].ToString(); this.Frame.Navigate(typeof(OndernemingenPage_Mobile)); ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTekstElementen = toastXml.GetElementsByTagName("text"); toastTekstElementen[0].AppendChild(toastXml.CreateTextNode("Welkom " + user.Gebruikersnaam + " :)")); IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "long"); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); } } }
private void LoadToast() { /* TESTING TOAST NOTIFICATIONS ON WP 8.1 IGNORE THIS * * * */ // Using the ToastText02 toast template. ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; // Retrieve the content part of the toast so we can change the text. XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); //Find the text component of the content XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); // Set the text on the toast. // The first line of text in the ToastText02 template is treated as header text, and will be bold. toastTextElements[0].AppendChild(toastXml.CreateTextNode("Sparklr")); toastTextElements[1].AppendChild(toastXml.CreateTextNode("Runninng, this is a test of the WP action center\nIt works")); // Set the duration on the toast IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "long"); // Create the actual toast object using this toast specification. ToastNotification toast = new ToastNotification(toastXml); toast.SuppressPopup = true; // Send the toast. ToastNotificationManager.CreateToastNotifier().Show(toast); }
// Note: All toast templates available in the Toast Template Catalog (http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx) // are treated as a ToastText02 template on Windows Phone. // That template defines a maximum of 2 text elements. The first text element is treated as header text and is always bold. // Images will never be downloaded when any of the other templates containing image elements are used, because Windows Phone will // not display the image. The app icon (Square 150 x 150) is displayed to the left of the toast text and is also show in the action center. public static ToastNotification CreateTextOnlyToast(string toastHeading, string toastBody) { // Using the ToastText02 toast template. ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; // Retrieve the content part of the toast so we can change the text. XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); //Find the text component of the content XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); // Set the text on the toast. // The first line of text in the ToastText02 template is treated as header text, and will be bold. toastTextElements[0].AppendChild(toastXml.CreateTextNode(toastHeading)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(toastBody)); // Set the duration on the toast IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "long"); // Create the actual toast object using this toast specification. ToastNotification toast = new ToastNotification(toastXml); return(toast); }
// To-Do: Check this class /// <summary> /// Create XmlDocument for given parametres /// </summary> /// <param name="text">Text on toast</param> /// <param name="template">Template of toast</param> /// <param name="imageSource">Image on toast</param> /// <returns>Toast notification XmlDocument</returns> public static XmlDocument GetXml(string[] text, ToastTemplateType template, string imageSource = null) { ToastTemplateType ToastTemplate = template; XmlDocument ToastXml = ToastNotificationManager.GetTemplateContent(ToastTemplate); XmlNodeList ToastElements; /* if (ImageSource != null) * { * ToastElements = ToastXml.GetElementsByTagName("image"); * * try * { * ToastElements[0].AppendChild(ToastXml.CreateTextNode(ImageSource)); * } * catch { } * }*/ ToastElements = ToastXml.GetElementsByTagName("text"); for (int i = 0; i < ToastElements.Length; i++) { ToastElements[i].AppendChild(ToastXml.CreateTextNode(text[i])); } return(ToastXml); }
public static void ShowToastNotification(string text) { // 1. create element ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); // 2. provide text XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(text)); // 3. provide image //XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); //((XmlElement)toastImageAttributes[0]).SetAttribute("src", $"ms-appx:///assets/{assetsImageFileName}"); //((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "logo"); // 4. duration IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "short"); // 5. audio //XmlElement audio = toastXml.CreateElement("audio"); //audio.SetAttribute("src", $"ms-winsoundevent:Notification.{audioName.ToString().Replace("_", ".")}"); //toastNode.AppendChild(audio); // 6. app launch parameter //((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"12345\",\"param2\":\"67890\"}"); // 7. send toast ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
public void Notify(string text, ToastTemplateType toastTemplateType, double duration, string imageUrl = null) { XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplateType); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); //Text Notification toastTextElements[0].InnerText = text; if (imageUrl != null) { XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImageAttributes[0]).SetAttribute("src", imageUrl); ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", text); } IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); //Create toast node so you can add separete audio and duration ((XmlElement)toastNode).SetAttribute("duration", "long"); //Toast Duration short or long [optional] ToastNotification toast = new ToastNotification(toastXml); //create object of toast notificaion toast.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(duration); //Auto remove Notificaiton [Optional] _toastNotifier.Show(toast); }
public static void ShowToast(string toastHeader, string message) { // setup the toast ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); if (String.IsNullOrEmpty(toastHeader)) { toastHeader = "PreInstallConfigTask"; } if (String.IsNullOrEmpty(message)) { message = "Task complete."; } XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(toastHeader)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(message)); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
public static void ShowToastNotification(string message) { ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); // Set Text XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(message)); // Set image // Images must be less than 200 KB in size and smaller than 1024 x 1024 pixels. XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///Images/logo-80px-80px.png"); ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "logo"); // toast duration IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "short"); // toast navigation var toastNavigationUriString = "#/MainPage.xaml?param1=12345"; var toastElement = ((XmlElement)toastXml.SelectSingleNode("/toast")); toastElement.SetAttribute("launch", toastNavigationUriString); // Create the toast notification based on the XML content you've specified. ToastNotification toast = new ToastNotification(toastXml); // Send your toast notification. ToastNotificationManager.CreateToastNotifier().Show(toast); }
void UpdateTemplateType() { if (type != ToastTemplateType.ToastGeneric) { if (type == ToastTemplateType.ToastText01) { type = ToastTemplateType.ToastImageAndText01; } if (type == ToastTemplateType.ToastText02) { type = ToastTemplateType.ToastImageAndText02; } if (type == ToastTemplateType.ToastText03) { type = ToastTemplateType.ToastImageAndText03; } if (type == ToastTemplateType.ToastText04) { type = ToastTemplateType.ToastImageAndText04; } } else if (!ToastNotificationManager.IsGenericTemplateSupported) { type = ToastTemplateType.ToastImageAndText04; } }
public static void ScheduleToast(ToastTemplateType toastTemplateType, string[] text, string image, DateTimeOffset deliveryTime) { var toastXml = CreateToastNotificationXml(toastTemplateType, text, image); var notification = new ScheduledToastNotification(toastXml, deliveryTime); ToastNotificationManager.CreateToastNotifier().AddToSchedule(notification); }
private ToastContent(ToastTemplateType toastTemplateType, string title, string content, string secondContent, string image, string altText, string launchArguments) { ToastTemplateType = toastTemplateType; Title = title; Content = content; SecondContent = secondContent; LaunchArguments = launchArguments; Image = image; AltText = altText; }
void DisplayWebImageToast(ToastTemplateType templateType) { IToastNotificationContent toastContent = null; string toastImageSrc = Scenario3ImageUrl.Text; if (templateType == ToastTemplateType.ToastImageAndText01) { IToastImageAndText01 templateContent = ToastContentFactory.CreateToastImageAndText01(); templateContent.TextBodyWrap.Text = "Body text that wraps"; templateContent.Image.Src = toastImageSrc; templateContent.Image.Alt = ALT_TEXT; toastContent = templateContent; } else if (templateType == ToastTemplateType.ToastImageAndText02) { IToastImageAndText02 templateContent = ToastContentFactory.CreateToastImageAndText02(); templateContent.TextHeading.Text = "Heading text"; templateContent.TextBodyWrap.Text = "Body text that wraps."; templateContent.Image.Src = toastImageSrc; templateContent.Image.Alt = ALT_TEXT; toastContent = templateContent; } else if (templateType == ToastTemplateType.ToastImageAndText03) { IToastImageAndText03 templateContent = ToastContentFactory.CreateToastImageAndText03(); templateContent.TextHeadingWrap.Text = "Heading text that wraps"; templateContent.TextBody.Text = "Body text"; templateContent.Image.Src = toastImageSrc; templateContent.Image.Alt = ALT_TEXT; toastContent = templateContent; } else if (templateType == ToastTemplateType.ToastImageAndText04) { IToastImageAndText04 templateContent = ToastContentFactory.CreateToastImageAndText04(); templateContent.TextHeading.Text = "Heading text"; templateContent.TextBody1.Text = "Body text"; templateContent.TextBody2.Text = "Another body text"; templateContent.Image.Src = toastImageSrc; templateContent.Image.Alt = ALT_TEXT; toastContent = templateContent; } rootPage.NotifyUser(toastContent.GetContent(), NotifyType.StatusMessage); // Create a toast from the Xml, then create a ToastNotifier object to show // the toast ToastNotification toast = toastContent.CreateNotification(); // If you have other applications in your package, you can specify the AppId of // the app to create a ToastNotifier for that application ToastNotificationManager.CreateToastNotifier().Show(toast); }
public static void ShowToast(ToastTemplateType toastTemplateType, string[] text, string image, DateTimeOffset? expirationTime, Action<string> OnToastDismissed, Action OnToastActivated, Action<Exception> OnToastFailed) { Windows.Data.Xml.Dom.XmlDocument toastXml = CreateToastNotificationXml(toastTemplateType, text, image); var notification = new ToastNotification(toastXml); if (OnToastDismissed != null) { notification.Dismissed += (sender, args) => { Utils.RunOnUnityAppThread(() => { OnToastDismissed(args.Reason.ToString()); }); }; } if (OnToastActivated != null) { notification.Activated += (sender, args) => { Utils.RunOnUnityAppThread(() => { OnToastActivated(); }); }; } if (OnToastFailed != null) { notification.Failed += (sender, args) => { Utils.RunOnUnityAppThread(() => { OnToastFailed(args.ErrorCode); }); }; } if (expirationTime != null) { if (expirationTime > DateTimeOffset.Now) { notification.ExpirationTime = expirationTime; } } ToastNotificationManager.CreateToastNotifier().Show(notification); }
void DisplayTextToast(ToastTemplateType templateType) { // Creates a toast using the notification object model, which is another project // in this solution. For an example using Xml manipulation, see the function // DisplayToastUsingXmlManipulation below. IToastNotificationContent toastContent = null; if (templateType == ToastTemplateType.ToastText01) { IToastText01 templateContent = ToastContentFactory.CreateToastText01(); templateContent.TextBodyWrap.Text = "Body text that wraps over three lines"; toastContent = templateContent; } else if (templateType == ToastTemplateType.ToastText02) { IToastText02 templateContent = ToastContentFactory.CreateToastText02(); templateContent.TextHeading.Text = "Heading text"; templateContent.TextBodyWrap.Text = "Body text that wraps over two lines"; toastContent = templateContent; } else if (templateType == ToastTemplateType.ToastText03) { IToastText03 templateContent = ToastContentFactory.CreateToastText03(); templateContent.TextHeadingWrap.Text = "Heading text that is very long and wraps over two lines"; templateContent.TextBody.Text = "Body text"; toastContent = templateContent; } else if (templateType == ToastTemplateType.ToastText04) { IToastText04 templateContent = ToastContentFactory.CreateToastText04(); templateContent.TextHeading.Text = "Heading text"; templateContent.TextBody1.Text = "First body text"; templateContent.TextBody2.Text = "Second body text"; toastContent = templateContent; } rootPage.NotifyUser(toastContent.GetContent(), NotifyType.StatusMessage); // Create a toast, then create a ToastNotifier object to show // the toast ToastNotification toast = toastContent.CreateNotification(); // If you have other applications in your package, you can specify the AppId of // the app to create a ToastNotifier for that application ToastNotificationManager.CreateToastNotifier().Show(toast); }
public void Notify(string text, ToastTemplateType toastTemplateType, double duration, string imageUrl = null) { XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplateType); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); //Text Notification toastTextElements[0].InnerText = text; if(imageUrl != null) { XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImageAttributes[0]).SetAttribute("src", imageUrl); ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", text); } IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); //Create toast node so you can add separete audio and duration ((XmlElement)toastNode).SetAttribute("duration", "long"); //Toast Duration short or long [optional] ToastNotification toast = new ToastNotification(toastXml); //create object of toast notificaion toast.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(duration); //Auto remove Notificaiton [Optional] _toastNotifier.Show(toast); }
public static void ScheduleToast(ToastTemplateType toastTemplateType, string[] text, string image, DateTimeOffset deliveryTime) { }
private static Windows.Data.Xml.Dom.XmlDocument CreateToastNotificationXml(ToastTemplateType toastTemplateType, string[] text, string image) { var toastXml = ToastNotificationManager.GetTemplateContent((Windows.UI.Notifications.ToastTemplateType)toastTemplateType); var textNodes = toastXml.GetElementsByTagName("text"); if (textNodes.Length != text.Length) { throw new ArgumentException("more text fields than supported by the template"); } for (int i = 0; i < textNodes.Length; i++) { textNodes[i].InnerText = text[i]; } // for a text only template, images will not be supplied. if ( !string.IsNullOrEmpty(image)) { var imageNodes = toastXml.GetElementsByTagName("image"); if (imageNodes.Length != 1) { throw new ArgumentException("invalid number of images"); } imageNodes[0].Attributes.GetNamedItem("src").NodeValue = image; } return toastXml; }
public static void ShowToast(ToastTemplateType toastTemplateType, string[] text, string image, DateTimeOffset? expirationTime) { ShowToast(toastTemplateType, text, image, expirationTime, null, null, null); }
public static void ShowToast(ToastTemplateType toastTemplateType, string[] text, string image) { ShowToast(toastTemplateType, text, image, null, null, null, null); }
public static void ScheduleToast(ToastTemplateType toastTemplateType, string[] text, DateTimeOffset deliveryTime) { ScheduleToast(toastTemplateType, text, null, deliveryTime); }
void DisplayTextToastWithStringManipulation(ToastTemplateType templateType) { string toastXmlString = String.Empty; if (templateType == ToastTemplateType.ToastText01) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText01'>" + "<text id='1'>Body text that wraps over three lines</text>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastText02) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText02'>" + "<text id='1'>Heading text</text>" + "<text id='2'>Body text that wraps over two lines</text>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastText03) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText03'>" + "<text id='1'>Heading text that is very long and wraps over two lines</text>" + "<text id='2'>Body text</text>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastText04) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='ToastText04'>" + "<text id='1'>Heading text</text>" + "<text id='2'>First body text</text>" + "<text id='3'>Second body text</text>" + "</binding>" + "</visual>" + "</toast>"; } Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument(); toastDOM.LoadXml(toastXmlString); rootPage.NotifyUser(toastDOM.GetXml(), NotifyType.StatusMessage); // Create a toast, then create a ToastNotifier object to show // the toast ToastNotification toast = new ToastNotification(toastDOM); // If you have other applications in your package, you can specify the AppId of // the app to create a ToastNotifier for that application ToastNotificationManager.CreateToastNotifier().Show(toast); }
void DisplayWebImageToastWithStringManipulation(ToastTemplateType templateType) { string toastXmlString = String.Empty; string toastImageSrc = Scenario3ImageUrl.Text; if (templateType == ToastTemplateType.ToastImageAndText01) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='toastImageAndText01'>" + "<text id='1'>Body text that wraps over three lines</text>" + "<image id='1' src='" + toastImageSrc + "' alt='" + ALT_TEXT + "'/>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastImageAndText02) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='toastImageAndText02'>" + "<text id='1'>Heading text</text>" + "<text id='2'>Body text that wraps over two lines</text>" + "<image id='1' src='" + toastImageSrc + "' alt='" + ALT_TEXT + "'/>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastImageAndText03) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='toastImageAndText03'>" + "<text id='1'>Heading text that wraps over two lines</text>" + "<text id='2'>Body text</text>" + "<image id='1' src='" + toastImageSrc + "' alt='" + ALT_TEXT + "'/>" + "</binding>" + "</visual>" + "</toast>"; } else if (templateType == ToastTemplateType.ToastImageAndText04) { toastXmlString = "<toast>" + "<visual version='1'>" + "<binding template='toastImageAndText04'>" + "<text id='1'>Heading text</text>" + "<text id='2'>First body text</text>" + "<text id='3'>Second body text</text>" + "<image id='1' src='" + toastImageSrc + "' alt='" + ALT_TEXT + "'/>" + "</binding>" + "</visual>" + "</toast>"; } Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument(); try { toastDOM.LoadXml(toastXmlString); rootPage.NotifyUser(toastDOM.GetXml(), NotifyType.StatusMessage); // Create a toast, then create a ToastNotifier object to show // the toast ToastNotification toast = new ToastNotification(toastDOM); // If you have other applications in your package, you can specify the AppId of // the app to create a ToastNotifier for that application ToastNotificationManager.CreateToastNotifier().Show(toast); } catch (Exception) { rootPage.NotifyUser("Error loading the xml, check for invalid characters in the input", NotifyType.ErrorMessage); } }
public static void DisplayTextToast(ToastTemplateType templateType, string fromId, string content = null, string imageUri = null) { // Creates a toast using the notification object model, which is another project // in this solution. For an example using Xml manipulation, see the function // DisplayToastUsingXmlManipulation below. IToastNotificationContent toastContent = null; if (templateType == ToastTemplateType.ToastText01) { IToastText01 templateContent = ToastContentFactory.CreateToastText01(); templateContent.TextBodyWrap.Text = "Body text that wraps over three lines"; toastContent = templateContent; } else if (templateType == ToastTemplateType.ToastText02) { IToastText02 templateContent = ToastContentFactory.CreateToastText02(); templateContent.TextHeading.Text = "Heading text"; templateContent.TextBodyWrap.Text = "Body text that wraps over two lines"; toastContent = templateContent; } else if (templateType == ToastTemplateType.ToastText03) { IToastText03 templateContent = ToastContentFactory.CreateToastText03(); templateContent.TextHeadingWrap.Text = "Heading text that is very long and wraps over two lines"; templateContent.TextBody.Text = "Body text"; toastContent = templateContent; } else if (templateType == ToastTemplateType.ToastText04) { IToastText04 templateContent = ToastContentFactory.CreateToastText04(); templateContent.TextHeading.Text = "Heading text"; templateContent.TextBody1.Text = "First body text"; templateContent.TextBody2.Text = "Second body text"; toastContent = templateContent; } else if (templateType == ToastTemplateType.ToastImageAndText01) { IToastImageAndText01 templateContent = ToastContentFactory.CreateToastImageAndText01(); if (String.IsNullOrWhiteSpace(content) == false) { templateContent.TextBodyWrap.Text = content; } else { templateContent.TextBodyWrap.Text = "text here!"; } if (String.IsNullOrWhiteSpace(imageUri) == false) { templateContent.Image.Src = imageUri; } else { templateContent.Image.Src = "http://singularlabs.com/wp-content/uploads/2011/11/System-Ninja-2.2.png"; } toastContent = templateContent; } // Create a toast, then create a ToastNotifier object to show // the toast ToastNotification toast = toastContent.CreateNotification(); Dictionary<String, String> args = new Dictionary<String, String>(); args.Add("fromId", fromId); args.Add("content", content); //toast.Activated += ToastTapped(toast, args); toast.Activated += new TypedEventHandler<ToastNotification, object>((sender, e) => ToastTapped(toast, args)); // If you have other applications in your package, you can specify the AppId of // the app to create a ToastNotifier for that application ToastNotificationManager.CreateToastNotifier().Show(toast); }
public static void ShowToast(ToastTemplateType toastTemplateType, string[] text, string image) { }
public static void ShowToast(ToastTemplateType toastTemplateType, string[] text, string image, DateTimeOffset? expirationTime, Action<string> OnToastDismissed, Action OnToastActivated, Action<Exception> OnToastFailed) { }
static WinRTToastNotificationContent Create(ToastTemplateType type, params string[] lines) { return new WinRTToastNotificationContent { type = type, lines = lines }; }
public Element_ToastBinding(ToastTemplateType template) { Template = template; }
public void SetImage(string imagePath) { if(type == ToastTemplateType.ToastText01) type = ToastTemplateType.ToastImageAndText01; if(type == ToastTemplateType.ToastText02) type = ToastTemplateType.ToastImageAndText02; if(type == ToastTemplateType.ToastText03) type = ToastTemplateType.ToastImageAndText03; if(type == ToastTemplateType.ToastText04) type = ToastTemplateType.ToastImageAndText04; CheckImagePath(imagePath); this.imagePath = imagePath; }