private void btnLocatToastWithAction_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { string title = "Você recebeu uma imagem"; string content = "Check this out, Happy Canyon in Utah!"; string image = "http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-71-81-permanent/2727.happycanyon1_5B00_1_5D00_.jpg"; string toastActions = $@"<toast> <visual> <binding template='ToastGeneric'> <text>{title}</text> <text>{content}</text> <image src='{image}' placement='appLogoOverride' hint-crop='circle'/> </binding> </visual> <actions> <input id = 'message' type = 'text' placeholderContent = 'reply here' /> <action activationType = 'background' content = 'reply' arguments = 'reply' /> <action activationType = 'foreground' content = 'video call' arguments = 'video' /> </actions> </toast>"; XmlDocument x = new XmlDocument(); x.LoadXml(toastActions); ToastNotification t = new ToastNotification(x); ToastNotificationManager.CreateToastNotifier().Show(t); }
private void OnSendNotification(object sender, RoutedEventArgs e) { string xml = @"<toast launch=""developer-defined-string""> <visual> <binding template=""ToastGeneric""> <image placement=""appLogoOverride"" src=""Assets/MicrosoftLogo.png"" /> <text>DotNet Spain Conference</text> <text>How much do you like my session?</text> </binding> </visual> <actions> <input id=""rating"" type=""selection"" defaultInput=""5"" > <selection id=""1"" content=""1 (Not very much)"" /> <selection id=""2"" content=""2"" /> <selection id=""3"" content=""3"" /> <selection id=""4"" content=""4"" /> <selection id=""5"" content=""5 (A lot!)"" /> </input> <action activationType=""background"" content=""Vote"" arguments=""vote"" /> </actions> </toast>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); ToastNotification toast = new ToastNotification(doc); ToastNotificationManager.CreateToastNotifier().Show(toast); }
public static async void actionsToast(string title, string content, string id) { string xml = "<toast>" + "<visual>" + "<binding template=\"ToastGeneric\">" + "<text></text>" + "<text></text>" + "</binding>" + "</visual>" + "<actions>" + "<input id=\"content\" type=\"text\" placeHolderContent=\"请输入评论\" />" + "<action content = \"确定\" arguments = \"ok" + id + "\" activationType=\"background\" />" + "<action content = \"取消\" arguments = \"cancel\" activationType=\"background\"/>" + "</actions >" + "</toast>"; // 创建并加载XML文档 XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNodeList elements = doc.GetElementsByTagName("text"); elements[0].AppendChild(doc.CreateTextNode(title)); elements[1].AppendChild(doc.CreateTextNode(content)); // 创建通知实例 ToastNotification notification = new ToastNotification(doc); //// 显示通知 //DateTime statTime = DateTime.Now.AddSeconds(10); //指定应传递 Toast 通知的时间 //ScheduledToastNotification recurringToast = new ScheduledToastNotification(doc, statTime); //创建计划的 Toast 通知对象 //ToastNotificationManager.CreateToastNotifier().AddToSchedule(recurringToast); //向计划中添加 Toast 通知 ToastNotifier nt = ToastNotificationManager.CreateToastNotifier(); nt.Show(notification); }
public static void ShowToast(string title, string message, [NotNull] Uri icon, Action click) { var tempIcon = FilesStorage.Instance.GetFilename("Temporary", "Icon.png"); if (!File.Exists(tempIcon)) { using (var iconStream = Application.GetResourceStream(icon)?.Stream) { if (iconStream != null) { using (var file = new FileStream(tempIcon, FileMode.Create)) { iconStream.CopyTo(file); } } } } var content = new XmlDocument(); content.LoadXml($@"<toast> <visual> <binding template=""ToastImageAndText02""> <image id=""1"" src=""file://{tempIcon}""/> <text id=""1"">{title}</text> <text id=""2"">{message}</text> </binding> </visual> </toast>"); var toast = new ToastNotification(content); if (click != null) { toast.Activated += (sender, args) => { Application.Current.Dispatcher.Invoke(click); }; } ToastNotifier.Show(toast); }
private static void ShowToast(params string[] messages) { // Get a toast XML template var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01); // Fill in the text elements var stringElements = toastXml.GetElementsByTagName("text"); for (var index = 0; index < messages.Length; index++) { stringElements[index].AppendChild(toastXml.CreateTextNode(messages[index])); } // Specify the absolute path to an image var imagePath = "file:///" + Path.GetFullPath("Resources/logo.png"); var imageElements = toastXml.GetElementsByTagName("image"); var namedItem = imageElements[0].Attributes.GetNamedItem("src"); if (namedItem != null) namedItem.NodeValue = imagePath; var toast = new ToastNotification(toastXml); //toast.Activated += ToastActivated; //toast.Dismissed += ToastDismissed; ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast); }
public void Run(IBackgroundTaskInstance taskInstance) { var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail; string arguments = details.Argument; var result = details.UserInput; if (arguments == "check") { int sum = int.Parse(result["message"].ToString()); string message = sum == 15 ? "Congratulations, the answer is correct!" : "Sorry, wrong answer!"; string xml = $@"<toast> <visual> <binding template=""ToastGeneric""> <image placement=""appLogoOverride"" src=""Assets/MicrosoftLogo.png"" /> <text>{message}</text> </binding> </visual> </toast>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); ToastNotification notification = new ToastNotification(doc); ToastNotificationManager.CreateToastNotifier().Show(notification); } }
private void ToastFailed(Windows.UI.Notifications.ToastNotification sender, ToastFailedEventArgs e) { //Dispatcher.Invoke(() => //{ // Output.Text = "The toast encountered an error."; //}); }
public async Task ShowAsync(string title, string text) { try { // prep for custom var folder = await Windows.ApplicationModel.Package.Current .InstalledLocation.GetFolderAsync("Services"); folder = await folder.GetFolderAsync("ToastService"); var file = await folder.GetFileAsync("SimpleToast.xml"); var xml = XDocument.Load(file.Path); // fetch targets var imageElement = xml.Descendants("image").First(); var titleElement = xml.Descendants("text").First(); var subtitleElement = xml.Descendants("text").ToArray()[1]; // set values var imagePath = new Uri("ms-appx://Services/ToastService/Template10.png"); imageElement.SetAttributeValue("src", imagePath.ToString()); titleElement.SetValue(title); subtitleElement.SetValue(text); // show var toastNotification = new ToastNotification(xml.ToXmlDocument()); var toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toastNotification); } catch (Exception) { System.Diagnostics.Debugger.Break(); } }
public static ToastNotification DisplayToast(string content) { string xml = $@"<toast activationType='foreground'> <visual> <binding template='ToastGeneric'> <text>Extended Execution</text> </binding> </visual> </toast>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); var binding = doc.SelectSingleNode("//binding"); var el = doc.CreateElement("text"); el.InnerText = content; binding.AppendChild(el); //Add content to notification var toast = new ToastNotification(doc); ToastNotificationManager.CreateToastNotifier().Show(toast); //Show the toast return toast; }
public static void NotifyMessageDeliveryFailed(Recipients recipients, long threadId) { var content = new ToastContent() { Launch = new QueryString() { {"action", "viewConversation" }, { "threadId", threadId.ToString() } }.ToString(), Visual = new ToastVisual() { TitleText = new ToastText() { Text = $"Message delivery failed" }, }, /*Audio = new ToastAudio() { Src = new Uri("ms-winsoundevent:Notification.IM") }*/ }; var doc = content.GetXml(); // Generate WinRT notification var noti = new ToastNotification(doc); ToastNotificationManager.CreateToastNotifier().Show(noti); }
void Logger_Logged(LogItem log) { var s = log.Timestamp.ToString() + " [" + log.PriorityLabel + "] " + log.Message; if (log.Exception != null) { s += ": " + log.Exception.Message + " Stack trace:\n" + log.Exception.StackTrace; } Debug.WriteLine(s); if (log.Priority == LogPriority.Error) { var toastTemplate = ToastTemplateType.ToastText02; var toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); toastXml.GetElementsByTagName("text")[0].AppendChild(toastXml.CreateTextNode(log.Message)); toastXml.GetElementsByTagName("text")[1].AppendChild(toastXml.CreateTextNode(log.Exception != null ? log.Exception.Message : "")); var toast = new ToastNotification(toastXml); //var toastNode = toastXml.SelectSingleNode("/toast"); //((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"12345\",\"param2\":\"67890\"}"); ToastNotificationManager.CreateToastNotifier().Show(toast); /*Window.Current.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { new MessageDialog(s, "Error").ShowAsync(); });*/ } }
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 Toast_Dismissed(Windows.UI.Notifications.ToastNotification sender, ToastDismissedEventArgs args) { #if WINDOWS_UWP var id = sender.Tag; #else var id = _toasts.Single(x => x.Value == sender).Key; #endif switch (args.Reason) { case ToastDismissalReason.ApplicationHidden: _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.ApplicationHidden }); break; case ToastDismissalReason.TimedOut: _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.Timeout }); break; case ToastDismissalReason.UserCanceled: default: _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.Dismissed }); break; } _resetEvents[id].Set(); }
public static void CreateToastNotification(ForumThreadEntity forumThread) { string replyText = forumThread.RepliesSinceLastOpened > 1 ? " has {0} replies." : " has {0} reply."; XmlDocument notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02); XmlNodeList toastElements = notificationXml.GetElementsByTagName("text"); toastElements[0].AppendChild( notificationXml.CreateTextNode(string.Format("\"{0}\"", forumThread.Name))); toastElements[1].AppendChild( notificationXml.CreateTextNode(string.Format(replyText, forumThread.RepliesSinceLastOpened))); XmlNodeList imageElement = notificationXml.GetElementsByTagName("image"); string imageName = string.Empty; if (string.IsNullOrEmpty(imageName)) { imageName = forumThread.ImageIconLocation; } imageElement[0].Attributes[1].NodeValue = imageName; IXmlNode toastNode = notificationXml.SelectSingleNode("/toast"); string test = "{" + string.Format("type:'toast', 'threadId':{0}", forumThread.ThreadId) + "}"; var xmlElement = (XmlElement)toastNode; if (xmlElement != null) xmlElement.SetAttribute("launch", test); var toastNotification = new ToastNotification(notificationXml); var nameProperty = toastNotification.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "Tag"); if (nameProperty != null) { nameProperty.SetValue(toastNotification, forumThread.ThreadId.ToString()); } ToastNotificationManager.CreateToastNotifier().Show(toastNotification); }
// Create and show the toast. private void Show(string notificationText, bool isActions) { // Get a toast XML template //XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04); var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01); // Fill in the text elements var stringElements = toastXml.GetElementsByTagName("text"); //for (int i = 0; i < stringElements.Length; i++) //{ // stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i)); //} stringElements[0].AppendChild(toastXml.CreateTextNode(notificationText)); // Specify the absolute path to an image var imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png"); var imageElements = toastXml.GetElementsByTagName("image"); imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath; // Create the toast and attach event listeners var toast = new Windows.UI.Notifications.ToastNotification(toastXml); if (isActions) { toast.Activated += ToastActivated; toast.Dismissed += ToastDismissed; toast.Failed += ToastFailed; } // Show the toast. Be sure to specify the AppUserModelId on your application's shortcut! ToastNotificationManager.CreateToastNotifier(AppId).Show(toast); }
public static void SendToast(string text) { //<toast> // <visual> // <binding template="ToastImageAndText01"> // <image id="1" src=""/> // <text id="1"></text> // </binding> // </visual> //</toast> var toastTemplate = ToastTemplateType.ToastImageAndText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(text)); XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///images/redWide.png"); ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "red graphic"); IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "long"); //IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); XmlElement audio = toastXml.CreateElement("audio"); audio.SetAttribute("src", "ms-winsoundevent:Notification.IM"); //audio.SetAttribute("silent", "true"); toastNode.AppendChild(audio); var toast = new ToastNotification(toastXml); 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; }
public static void Notify(int usagePerc, string quotaName) { var xmlDoc = CreateToast(usagePerc, quotaName); var notifier = ToastNotificationManager.CreateToastNotifier(); var toast = new ToastNotification(xmlDoc); notifier.Show(toast); }
private void ShowToast() { // GetTemplateContent returns a Windows.Data.Xml.Dom.XmlDocument object containing // the toast XML XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText04); XmlElement xe = toastXml.CreateElement("title"); // You can use the methods from the XML document to specify all of the // required parameters for the toast XmlNodeList stringElements = toastXml.GetElementsByTagName("text"); for (uint i = 0; i < stringElements.Length; i++) { stringElements.Item(i).AppendChild(toastXml.CreateTextNode("测试 !")); } // Create a toast from the Xml, then create a ToastNotifier object to show // the toast ToastNotification toast = new ToastNotification(toastXml); // 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); }
static public void Popup(string s, int imgID = 0) { var toastXML = manager.GetTemplateContent(note.ToastTemplateType.ToastImageAndText01); var imgtag = toastXML.GetElementsByTagName("image"); string ss = "./img/"; if (imgID == 0) { ss += "logo.ico"; } else if (imgID == 1) { ss += "ok.png"; } else { ss += "error.png"; } imgtag[0].Attributes.GetNamedItem("src").NodeValue = "file:///" + Path.GetFullPath(ss); var texttag = toastXML.GetElementsByTagName("text"); texttag[0].AppendChild(toastXML.CreateTextNode(s)); toast = new note.ToastNotification(toastXML); manager.CreateToastNotifier(sub_title).Show(toast); }
private static void SendToast() { //prepare collection List<HolidayItem> collection = _manager.GetHolidayList(DateTime.Now); collection = collection.Where(p => p.Day == SelectedDate.Day || p.HolidayName == "google calendar").ToList(); if (collection.Count > 0) { foreach (var item in collection) { // 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(SelectedDate.ToString("d"))); toastTextElements[1].AppendChild(toastXml.CreateTextNode(item.HolidayName)); // 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); ToastNotificationManager.CreateToastNotifier().Show(toast); } } }
public static void Simple(string textline1, string title = "HFR10") { var content = new ToastContent(); content.Visual = new ToastVisual() { TitleText = new ToastText() { Text = title, }, BodyTextLine1 = new ToastText() { Text = textline1, } }; content.Audio = new ToastAudio() { Src = new Uri("ms-winsoundevent:Notification.IM") }; XmlDocument doc = content.GetXml(); // Generate WinRT notification var toast = new ToastNotification(doc); toast.ExpirationTime = DateTimeOffset.Now.AddSeconds(30); ToastNotificationManager.CreateToastNotifier().Show(toast); }
public static void ShowToast(string message, string imageRelativePath = null) { XmlDocument toastXml; if (imageRelativePath != null) { ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImageAttributes.First()).SetAttribute("src", "ms-appx:///" + imageRelativePath); ((XmlElement)toastImageAttributes.First()).SetAttribute("alt", "toast image"); } else { ToastTemplateType toastTemplate = ToastTemplateType.ToastText01; toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); } XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements.First().AppendChild(toastXml.CreateTextNode(message)); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
/// <summary> /// 弹出通知toast,使用方法:ShowToastNotification("Square150x150Logo.scale-200.png", $"已复制 {val}", NotificationAudioNames.Default); /// </summary> /// <param name="assetsImageFileName">在Asserts根目录下的图片名称,注意必须在Assets文件夹下,具体参见源码</param> /// <param name="text">通知的文本信息</param> /// <param name="audioName">通知的声音,源码有自定义枚举</param> /// 来源:http://edi.wang/post/2015/11/8/uwp-toast-notification public static void ShowToastNotification(string assetsImageFileName, string text, NotificationAudioNames audioName) { // 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 static void UpdateTile(int value) { var type = BadgeTemplateType.BadgeNumber; var xml = BadgeUpdateManager.GetTemplateContent(type); var elements = xml.GetElementsByTagName("badge"); var element = elements[0] as XmlElement; element.SetAttribute("value", value.ToString()); var updater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); var notification = new BadgeNotification(xml); updater.Update(notification); Debug.WriteLine("Background task badge updated: " + value.ToString()); var template = ToastTemplateType.ToastText01; xml = ToastNotificationManager.GetTemplateContent(template); var text = xml.CreateTextNode(string.Format("Badge updated to {0}", value)); elements = xml.GetElementsByTagName("text"); elements[0].AppendChild(text); var toast = new ToastNotification(xml); var notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(toast); Debug.WriteLine("Background task toast shown: " + value.ToString()); }
void Scenario5DisplayToastWithCallbacks_Click(object sender, RoutedEventArgs e) { IToastText02 toastContent = ToastContentFactory.CreateToastText02(); // Set the launch activation context parameter on the toast. // The context can be recovered through the app Activation event toastContent.Launch = "Context123"; toastContent.TextHeading.Text = "Tap toast"; toastContent.TextBodyWrap.Text = "Or swipe to dismiss"; // You can listen for the "Activated" event provided on the toast object // or listen to the "OnLaunched" event off the Windows.UI.Xaml.Application // object to tell when the user clicks the toast. // // The difference is that the OnLaunched event will // be raised by local, scheduled and cloud toasts, while the event provided by the // toast object will only be raised by local toasts. // // In this example, we'll use the event off the CoreApplication object. scenario5Toast = toastContent.CreateNotification(); scenario5Toast.Dismissed += toast_Dismissed; scenario5Toast.Failed += toast_Failed; ToastNotificationManager.CreateToastNotifier().Show(scenario5Toast); }
private void Initialize() { // Clear all existing notifications ToastNotificationManager.History.Clear(); var longTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longtime"); DateTimeOffset expiryTime = DateTime.Now.AddSeconds(30); string expiryTimeString = longTime.Format(expiryTime); XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); //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("Expiring Toast")); toastTextElements[1].AppendChild(toastXml.CreateTextNode("It will expire at " + expiryTimeString)); // 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.ExpirationTime = expiryTime; // Send the toast. ToastNotificationManager.CreateToastNotifier().Show(toast); }
void InvokeSimpleToast(string messageReceived) { // GetTemplateContent returns a Windows.Data.Xml.Dom.XmlDocument object containing // the toast XML XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); // You can use the methods from the XML document to specify all of the // required parameters for the toast. XmlNodeList stringElements = toastXml.GetElementsByTagName("text"); stringElements.Item(0).AppendChild(toastXml.CreateTextNode("Push notification message:")); stringElements.Item(1).AppendChild(toastXml.CreateTextNode(messageReceived)); // If comment out the next lines, the toast still makes noise. //// Audio tags are not included by default, so must be added to the XML document. //string audioSrc = "ms-winsoundevent:Notification.IM"; //XmlElement audioElement = toastXml.CreateElement("audio"); //audioElement.SetAttribute("src", audioSrc); //IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); //toastNode.AppendChild(audioElement); // Create a toast from the Xml, then create a ToastNotifier object to show the toast. var sdfg = toastXml.GetXml(); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
static async Task<bool?> ShowCore(XmlDocument rpDocument) { var rCompletionSource = new TaskCompletionSource<bool?>(); var rNotification = new ToastNotification(rpDocument); TypedEventHandler<ToastNotification, object> rActivated = (s, e) => rCompletionSource.SetResult(true); rNotification.Activated += rActivated; TypedEventHandler<ToastNotification, ToastDismissedEventArgs> rDismissed = (s, e) => rCompletionSource.SetResult(false); rNotification.Dismissed += rDismissed; TypedEventHandler<ToastNotification, ToastFailedEventArgs> rFailed = (s, e) => rCompletionSource.SetResult(null); rNotification.Failed += rFailed; r_Notifier.Show(rNotification); var rResult = await rCompletionSource.Task; rNotification.Activated -= rActivated; rNotification.Dismissed -= rDismissed; rNotification.Failed -= rFailed; return rResult; }
public void Hide() { if (_toast == null) return; ToastNotificationManager.CreateToastNotifier(_applicationId).Hide(_toast); _toast = null; }
private void DisplayToast(IBackgroundTaskInstance taskInstance) { try { SmsReceivedEventDetails smsDetails = (SmsReceivedEventDetails)taskInstance.TriggerDetails; SmsBinaryMessage smsEncodedmsg = smsDetails.BinaryMessage; SmsTextMessage smsTextMessage = Windows.Devices.Sms.SmsTextMessage.FromBinaryMessage(smsEncodedmsg); XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); XmlNodeList stringElements = toastXml.GetElementsByTagName("text"); stringElements.Item(0).AppendChild(toastXml.CreateTextNode(smsTextMessage.From)); stringElements.Item(1).AppendChild(toastXml.CreateTextNode(smsTextMessage.Body)); ToastNotification notification = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(notification); } catch (Exception ex) { Debug.WriteLine("Error displaying toast: " + ex.Message); } }
static TaskCompletionSource<bool?> GenerateTcs(ToastNotification notification) { var tcs = new TaskCompletionSource<bool?>(); notification.Dismissed += (sender, args) => tcs.SetResult(false); notification.Activated += (sender, args) => tcs.SetResult(true); notification.Failed += (sender, args) => tcs.SetException(args.ErrorCode); return tcs; }
public void showGhostNotification(BookQuote bq) { quote = bq; var toastDescriptor = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var txtNodes = toastDescriptor.GetElementsByTagName("text"); txtNodes[0].AppendChild(toastDescriptor.CreateTextNode(bq.Header)); txtNodes[1].AppendChild(toastDescriptor.CreateTextNode(bq.Content)); var toast = new ToastNotification(toastDescriptor); // add tag/group is needed Random r = new Random(); toast.Group = r.Next().ToString(); toast.Tag = r.Next().ToString() ; // Ghost toast //toast.SuppressPopup = true; toast.Activated += toast_Activated; var toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toast); }
void DisplayLongToast(bool loopAudio) { IToastText02 toastContent = ToastContentFactory.CreateToastText02(); // Toasts can optionally be set to long duration toastContent.Duration = ToastDuration.Long; toastContent.TextHeading.Text = "Long Duration Toast"; if (loopAudio) { toastContent.Audio.Loop = true; toastContent.Audio.Content = ToastAudioContent.LoopingAlarm; toastContent.TextBodyWrap.Text = "Looping audio"; } else { toastContent.Audio.Content = ToastAudioContent.IM; } scenario6Toast = toastContent.CreateNotification(); ToastNotificationManager.CreateToastNotifier().Show(scenario6Toast); rootPage.NotifyUser(toastContent.GetContent(), NotifyType.StatusMessage); }
private void ToastActivated(Windows.UI.Notifications.ToastNotification sender, object e) { //Dispatcher.Invoke(() => //{ // Activate(); // Output.Text = "The user activated the toast."; //}); }
private void Toast_Failed(Windows.UI.Notifications.ToastNotification sender, ToastFailedEventArgs args) { var id = sender.Tag; _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.Failed }); _resetEvents[id].Set(); }
private void Toast_Failed(Windows.UI.Notifications.ToastNotification sender, ToastFailedEventArgs args) { #if WINDOWS_UWP var id = sender.Tag; #else var id = _toasts.Single(x => x.Value == sender).Key; #endif _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.Failed }); _resetEvents[id].Set(); }
private static void ToastDismissed(Windows.UI.Notifications.ToastNotification sender, ToastDismissedEventArgs e) { switch (e.Reason) { case ToastDismissalReason.ApplicationHidden: break; case ToastDismissalReason.UserCanceled: break; case ToastDismissalReason.TimedOut: break; } }
private void Toast_Dismissed(Windows.UI.Notifications.ToastNotification sender, ToastDismissedEventArgs args) { var id = sender.Tag; var options = _notificationOptions[id]; if (args.Reason != ToastDismissalReason.UserCanceled && options.AllowTapInNotificationCenter) { return; } switch (args.Reason) { case ToastDismissalReason.ApplicationHidden: _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.ApplicationHidden }); break; case ToastDismissalReason.TimedOut: _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.Timeout }); break; case ToastDismissalReason.UserCanceled: default: _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.Dismissed }); break; } if (_notificationOptions.ContainsKey(id)) { if (options.ClearFromHistory) { ToastNotificationManager.History.Remove(id); } _notificationOptions.Remove(id); } _resetEvents[id].Set(); }
private void Toast_Dismissed(Windows.UI.Notifications.ToastNotification sender, ToastDismissedEventArgs args) { #if WINDOWS_UWP var id = sender.Tag; #else var id = _toasts.Single(x => x.Value == sender).Key; #endif switch (args.Reason) { case ToastDismissalReason.ApplicationHidden: _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.ApplicationHidden }); break; case ToastDismissalReason.TimedOut: _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.Timeout }); break; case ToastDismissalReason.UserCanceled: default: _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.Dismissed }); break; } if (_notificationOptions.ContainsKey(id)) { var options = _notificationOptions[id]; if (options.ClearFromHistory) { ToastNotificationManager.History.Remove(id); } _notificationOptions.Remove(id); } _resetEvents[id].Set(); }
public static void appClosing() { string toastXmlString = $@"<toast><visual> <binding template='ToastGeneric'> <text>O melembre está sendo executado em segundo plano</text> </binding> </visual></toast>"; var xmlDoc = new Windows.Data.Xml.Dom.XmlDocument(); xmlDoc.LoadXml(toastXmlString); var toastNotification = new Windows.UI.Notifications.ToastNotification(xmlDoc); var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier(); toastNotification.ExpiresOnReboot = true; toastNotification.Priority = ToastNotificationPriority.Default; toastNotifier.Show(toastNotification); }
public void Notify() { string xml = $@" <toast> <visual> <binding template='ToastGeneric'> <text>Some title</text> <text>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</text> </binding> </visual> </toast>"; var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); var toast = new Windows.UI.Notifications.ToastNotification(xmlDoc); ToastNotificationManager.CreateToastNotifier("WatchMyPrices").Show(toast); }
public static void ReminderAdd(Reminder reminder) { string toastXmlString = $@"<toast><visual> <binding template='ToastGeneric'> <text>Novo lembrete Definido</text> <text>{reminder.Reminder_text} para as {reminder._Horario} Prioridade {reminder.Priority}</text> </binding> </visual></toast>"; var xmlDoc = new Windows.Data.Xml.Dom.XmlDocument(); xmlDoc.LoadXml(toastXmlString); var toastNotification = new Windows.UI.Notifications.ToastNotification(xmlDoc); var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier(); toastNotification.Priority = ToastNotificationPriority.High; toastNotification.ExpiresOnReboot = false; toastNotifier.Show(toastNotification); }
public static void rememberingDelay(Reminder reminder) { string toastXmlString = $@"<toast><visual> <binding template='ToastGeneric'> <text>{reminder.Reminder_text}</text> <text>Em 1 hora</text> </binding> </visual></toast>"; var xmlDoc = new Windows.Data.Xml.Dom.XmlDocument(); xmlDoc.LoadXml(toastXmlString); var toastNotification = new Windows.UI.Notifications.ToastNotification(xmlDoc); var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier(); toastNotification.ExpiresOnReboot = false; toastNotification.Priority = ToastNotificationPriority.High; toastNotifier.Show(toastNotification); }
private void Toast_Activated(Windows.UI.Notifications.ToastNotification sender, object args) { lock (_eventLock) { var id = sender.Tag; if (!_eventResult.ContainsKey(id)) { _eventResult.Add(id, new NotificationResult() { Action = NotificationAction.Clicked }); } if (_resetEvents.ContainsKey(id)) { _resetEvents[id].Set(); } } }
public void ShowToast(string message = "File not found") { var image = "https://raw.githubusercontent.com/Windows-XAML/Template10/master/Assets/Template10.png"; var content = new NotificationsExtensions.Toasts.ToastContent() { Launch = "", Visual = new NotificationsExtensions.Toasts.ToastVisual() { BindingGeneric = new ToastBindingGeneric() { AppLogoOverride = new ToastGenericAppLogo { HintCrop = ToastGenericAppLogoCrop.Circle, Source = image }, Children = { new AdaptiveText { Text = "File not found." } }, Attribution = new ToastGenericAttributionText { Text = "Request Cancelled." }, } }, Audio = new NotificationsExtensions.Toasts.ToastAudio() { Src = new Uri("ms-winsoundevent:Notification.IM") } }; var notification = new Windows.UI.Notifications.ToastNotification(content.GetXml()); var notifier = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier(); notifier.Show(notification); }
private void ToastDismissed(Windows.UI.Notifications.ToastNotification sender, ToastDismissedEventArgs e) { String outputText = ""; switch (e.Reason) { case ToastDismissalReason.ApplicationHidden: outputText = "The app hid the toast using ToastNotifier.Hide"; break; case ToastDismissalReason.UserCanceled: outputText = "The user dismissed the toast"; break; case ToastDismissalReason.TimedOut: outputText = "The toast has timed out"; break; } //Dispatcher.Invoke(() => //{ // Output.Text = outputText; //}); }
private static void ToastFailed(Windows.UI.Notifications.ToastNotification sender, ToastFailedEventArgs e) { }
private void ToastActivated(Windows.UI.Notifications.ToastNotification sender, object e) { _exeWithParCmd?.Invoke(_parForExe); _exeCmd?.Invoke(); }
public Task <INotificationResult> Notify(INotificationOptions options) { return(Task.Run(() => { ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(options.Title)); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(options.Description)); Windows.Data.Xml.Dom.IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); var id = _count.ToString(); var root = toastXml.DocumentElement; root.SetAttribute("launch", id.ToString()); if (!string.IsNullOrEmpty(options.WindowsOptions.LogoUri)) { Windows.Data.Xml.Dom.XmlElement image = toastXml.CreateElement("image"); image.SetAttribute("placement", "appLogoOverride"); var imageUri = options.WindowsOptions.LogoUri; if (!options.WindowsOptions.LogoUri.Contains("//")) { imageUri = $"ms-appx:///{options.WindowsOptions.LogoUri}"; } image.SetAttribute("src", imageUri); toastXml.GetElementsByTagName("binding")[0].AppendChild(image); toastXml.GetElementsByTagName("binding")[0].Attributes[0].InnerText = "ToastGeneric"; } if (options.DelayUntil.HasValue) { ScheduledToastNotification toast = new ScheduledToastNotification(toastXml, options.DelayUntil.Value); ToastNotifier.AddToSchedule(toast); return new NotificationResult() { Action = NotificationAction.NotApplicable }; } else { Windows.UI.Notifications.ToastNotification toast = new Windows.UI.Notifications.ToastNotification(toastXml); toast.Tag = id; _count++; toast.Dismissed += Toast_Dismissed; toast.Activated += Toast_Activated; toast.Failed += Toast_Failed; _notificationOptions.Add(id, options); var waitEvent = new ManualResetEvent(false); _resetEvents.Add(id, waitEvent); ToastNotifier.Show(toast); waitEvent.WaitOne(); INotificationResult result = _eventResult[id]; if (!options.IsClickable && result.Action == NotificationAction.Clicked) // A click is transformed to manual dismiss { result = new NotificationResult() { Action = NotificationAction.Dismissed } } ; if (_resetEvents.ContainsKey(id)) { _resetEvents.Remove(id); } if (_eventResult.ContainsKey(id)) { _eventResult.Remove(id); } if (_notificationOptions.ContainsKey(id)) { _notificationOptions.Remove(id); } return result; } })); }