public static void CreateDefferedToast() { // Construct the visuals of the toast (using Notifications library) ToastContent toastContent = new ToastContent() { // Arguments when the user taps body of toast Launch = "action=viewConversation&conversationId=5", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Hello world!" } } } } }; // Create the XML document (BE SURE TO REFERENCE WINDOWS.DATA.XML.DOM) var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification var toast = new ScheduledToastNotification(toastContent.GetXml(), DateTime.Now.AddSeconds(10)); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().AddToSchedule(toast); }
public static void SendToastNotification(string Title, string line1, string line2, ToastTemplateType type) { if (!Enabled) { return; } try { //windows 10 allows max 3 lines var xml = $@"<toast> <visual> <binding template=""{type}""> <text id=""1"">{Title}</text> <text id=""2"">{line1}</text> <text id=""3"">{line2}</text> </binding> </visual> </toast>"; var toastXml = new XmlDocument(); toastXml.LoadXml(xml); var toast = new ToastNotification(toastXml); toast.Failed += (o, args) => { //TODO: add logs var message = args.ErrorCode; }; DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); } catch (Exception ex) { } }
public void CreateAndShowMessage(string message) { ToastContent toastContent = new ToastContent() { Launch = "bodyTapped", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = message }, } } }, Header = new ToastHeader("header", "NetStalker", "header") }; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); var messageNotification = new ToastNotification(doc); DesktopNotificationManagerCompat.CreateToastNotifier().Show(messageNotification); }
private void SendToast() { string title = "featured picture of the day"; string content = "beautiful scenery"; string image = "https://picsum.photos/360/180?image=104"; string logo = "https://picsum.photos/64?image=883"; string launch = "action=viewConversation"; string xmlString = $@"<toast><visual> <binding template='ToastGeneric' launch='{launch}'> <text>{title}</text> <text>{content}</text> <image src='{image}'/> <image src='{logo}' placement='appLogoOverride' hint-crop='circle'/> </binding> </visual></toast>"; XmlDocument toastXml = new XmlDocument(); toastXml.LoadXml(xmlString); ToastNotification toast = new ToastNotification(toastXml); //ToastNotificationManager.CreateToastNotifier().Show(toast); DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
public static void SendToast(string text) { // Construct the visuals of the toast (using Notifications library) ToastContent toastContent = new ToastContent() { // Arguments when the user taps body of toast Launch = "action=viewConversation&conversationId=5", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = text } } } } }; // Create the XML document (BE SURE TO REFERENCE WINDOWS.DATA.XML.DOM) var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification var toast = new ToastNotification(doc); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
private void ShowToast(string msg) { // Construct the visuals of the toast ToastContent toastContent = new ToastContent() { // Arguments when the user taps body of toast Launch = "action=ok", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = msg } } } } }; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification var toast = new ToastNotification(doc); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
private void DisplayToast(string toastXmlString, TypedEventHandler <ToastNotification, Object> activationHandler = null) { try { // Parse to XML XmlDocument toastXml = new XmlDocument(); toastXml.LoadXml(toastXmlString); // Setup Toast ToastNotification toast = new ToastNotification(toastXml); if (activationHandler != null) { toast.Activated += activationHandler; } // Display Toast DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); _log.Information(LogHelper.GetMethodName(this), $"{toast.Content.FirstChild.Attributes[0].NodeValue.ToString()} - Displayed successfully"); } catch (Exception ex) { _log.Error(LogHelper.GetMethodName(this), ex); } }
public void notify(string title, string description) { // Construct the visuals of the toast (using Notifications library) ToastContent toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = description } } } } }; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); var toast = new ToastNotification(doc); DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
public UwpToastNotifier() { Instance = this; CreateShortcut <MyNotificationActivator>(AppId, _appName, true); DesktopNotificationManagerCompat.RegisterAumidAndComServer <MyNotificationActivator>(AppId); DesktopNotificationManagerCompat.RegisterActivator <MyNotificationActivator>(); _toastNotifier = DesktopNotificationManagerCompat.CreateToastNotifier(); DesktopNotificationManagerCompat.History.Clear(); }
public void ShowNotification(string text) { Application.Current.Dispatcher.Invoke(() => { ToastContent toastContent = new ToastContentBuilder() .AddText(text) .GetToastContent(); var toast = new ToastNotification(toastContent.GetXml()); DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }); }
private void ShowNotification(string title, string message, bool retry, bool changePort) { ToastContent toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = message } } } } }; ToastActionsCustom buttons = new ToastActionsCustom(); buttons.Buttons.Add(new ToastButton("Stop", "stop")); if (retry) { buttons.Buttons.Add(new ToastButton("Retry", "retry")); } if (changePort) { buttons.Buttons.Add(new ToastButton("Change Port", "changePort")); ToastSelectionBox portBox = new ToastSelectionBox("portBox"); foreach (var port in SerialPort.GetPortNames()) { portBox.Items.Add(new ToastSelectionBoxItem(port, port)); } buttons.Inputs.Add(portBox); } toastContent.Actions = buttons; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); var toast = new ToastNotification(doc); DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
/// <summary> /// Send toast notification. /// </summary> /// <param name="toastContent">XML document of the toast notification</param> private static void SendNotification(ToastContent toastContent) { // Make sure to use Windows.Data.Xml.Dom XmlDocument doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification ToastNotification toast = new ToastNotification(doc); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
private void Button_Click(object sender, RoutedEventArgs e) { // トーストを組み立てる ToastContent toastContent = new ToastContentBuilder() .AddToastActivationInfo("action=viewConversation&conversationId=5", ToastActivationType.Foreground) .AddText("Hello world!") .GetToastContent(); // 組み立てたやつをもとにToastNotificationを作成 var toast = new ToastNotification(toastContent.GetXml()); // トーストを表示 DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
public void ShowNotification(string text, string secondaryText = null) { var builder = new ToastContentBuilder().AddText(text); if (!string.IsNullOrWhiteSpace(secondaryText)) { builder.AddText(secondaryText); } Application.Current.Dispatcher.Invoke(() => { var toast = new ToastNotification(builder.GetToastContent().GetXml()); DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }); }
/// <summary> /// Displays toast notification using the MS Windows toast service. /// </summary> /// <param name="message">Message to show to the user.</param> public void ShowNotification(string message) { // Specify message var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04); var stringElements = toastXml.GetElementsByTagName("text"); stringElements[1].AppendChild(toastXml.CreateTextNode(message)); // Specify the absolute path to an image var dir = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Resources", "zombie_64x64.png"); var imagePath = "file:///" + dir; var imageElements = toastXml.GetElementsByTagName("image"); imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath; // Create the toast notification var toast = new ToastNotification(toastXml); // Show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
public static void ShowToast(string title, string message, string testing = null) { var logger = Locator.Current.GetService <ILogger>(); try { if (!string.IsNullOrWhiteSpace(testing)) { testing = $"\nCode [{testing}]"; } var toastXmlString = $@"<toast> <visual> <binding template='ToastGeneric'> <text>{title}</text> <text>{message}</text> <text>{testing}</text> <text placement='attribution'>DFAssist</text> </binding> </visual> </toast>" .Replace("\r\n", string.Empty) .Replace("\t", string.Empty); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(toastXmlString); var toast = new ToastNotification(xmlDoc); var toastNotifier = DesktopNotificationManagerCompat.CreateToastNotifier(); toastNotifier.Show(toast); logger.Write("UI: Toast Showing!", LogLevel.Debug); } catch (Exception e) { logger.Write(e, "UI: Unable to show the toast...", LogLevel.Error); throw; } }
static void ShowOutdatedNotification(int num, string pcks) { Log.Debug("Show outdated notification. Packages: {Packages}", pcks); // enforce max length if (pcks.Length > 103) { pcks = pcks.Substring(0, 100) + "..."; } // Construct the content var updateAll = new ToastButton("Update all", CunNotificationActivator.UpdateAllAction); updateAll.ActivationType = ToastActivationType.Background; var update = new ToastButton("Update", CunNotificationActivator.UpdateAction); update.ActivationType = ToastActivationType.Background; var content = new ToastContentBuilder() .AddToastActivationInfo("list", ToastActivationType.Background) .AddHeader(MsgId, $"Chocolatey Packages outdated: {num}", "list") .AddText(pcks, AdaptiveTextStyle.Body) .AddButton(updateAll) .AddButton(update) .GetToastContent(); // Create the notification var notif = new ToastNotification(content.GetXml()) { ExpirationTime = DateTimeOffset.Now.AddMinutes(10) }; notif.Dismissed += Notif_Dismissed; // And show it! var oNotifier = DesktopNotificationManagerCompat.CreateToastNotifier(); oNotifier.Show(notif); }
public static void Show(string Message) { if (Settings.Default.MessageBox) { MessageBox.Show(Message, "WindowsRestAPI", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } if (Settings.Default.NotificationCenter) { // Construct the visuals of the toast (using Notifications library) ToastContent toastContent = new ToastContentBuilder() .AddToastActivationInfo("action=viewConversation&conversationId=5", ToastActivationType.Foreground) .AddText(Message) .GetToastContent(); // And create the toast notification var toast = new ToastNotification(toastContent.GetXml()); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); } }
private void SendButton_Click(object sender, EventArgs e) { try { // Construct the visuals of the toast (using Notifications library) ToastContent toastContent = new ToastContentBuilder() .AddToastActivationInfo("", ToastActivationType.Protocol) .AddText("Hello world!") .GetToastContent(); // And create the toast notification var toast = new ToastNotification(toastContent.GetXml()); Debug.WriteLine(toastContent.GetContent()); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); } catch (Exception exception) { Debug.WriteLine("Send to debug output."); Debug.WriteLine(exception.ToString()); } }
public void notify(string group, string identifier, string title, string description) { var toastContent = new ToastContent { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = description } } } } }; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); var toast = new ToastNotification(doc); if (!string.IsNullOrWhiteSpace(identifier)) { toast.Tag = identifier; toast.SuppressPopup = history.GetHistory().Any(GetToastComparer(toast)); } DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
public void CreateAndShowPrompt(string message) { ToastContent toastContent = new ToastContent() { Launch = "bodyTapped", Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = message }, } } }, Actions = new ToastActionsCustom() { Buttons = { new ToastButton("Yes", "Yes"), new ToastButton("No", "No") } }, Header = new ToastHeader("header", "NetStalker", "header") }; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); var promptNotification = new ToastNotification(doc); promptNotification.Activated += PromptNotificationOnActivated; DesktopNotificationManagerCompat.CreateToastNotifier().Show(promptNotification); }
private void OnTimedEvent(Object source, ElapsedEventArgs e) { client.Send(notCityName); string[] data; string recivedString; recivedString = client.Read(); data = recivedString.Split('|'); String notString = String.Format("Pogoda dla {0}, temp {1}°C, ciśn {2} hPa, wilg {3}%, wiatr {4} km/h", notCityName, data[2], data[3], data[4], data[5]); DesktopNotificationManagerCompat.RegisterAumidAndComServer <NotificationHandler>("Twoja Pogodynka"); DesktopNotificationManagerCompat.RegisterActivator <NotificationHandler>(); ToastContent toastContent = new ToastContentBuilder() .AddToastActivationInfo("", ToastActivationType.Background) .AddText(notString) .GetToastContent(); // And create the toast notification var toast = new ToastNotification(toastContent.GetXml()); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
private void CreateNotification(object sender, RoutedEventArgs e) { ToastContent content = new ToastContent() { // Arguments provided to the app when the notification is selected Launch = new QueryString() { { "action", "null" } }.ToString(), // Visual component of the notification Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "New Notification Message", HintMaxLines = 1 }, new AdaptiveText() { Text = "This test will make sure that notifications are working properly." } }, Attribution = new ToastGenericAttributionText() { Text = "Via App" } } }, // Actions the user can perform from the notification Actions = new ToastActionsCustom() { Buttons = { new ToastButton("View Activity", "action=null") { ActivationType = ToastActivationType.Foreground }, new ToastButton("Mark As Complete", "action=null") { ActivationType = ToastActivationType.Background } } } }; // Create and show the notification //ToastNotification toast = new ToastNotification(content.GetXml()); //DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); // Create a scheduled notification ScheduledToastNotification toast = new ScheduledToastNotification(content.GetXml(), DateTime.Now.AddSeconds(5)); DesktopNotificationManagerCompat.CreateToastNotifier().AddToSchedule(toast); }
private async void ButtonPopToast_Click(object sender, RoutedEventArgs e) { string title = "Andrew sent you a picture"; string content = "Check this out, The Enchantments!"; string image = "https://picsum.photos/364/202?image=883"; int conversationId = 5; // Construct the toast content ToastContent toastContent = new ToastContent() { // Arguments when the user taps body of toast Launch = new QueryString() { { "action", "viewConversation" }, { "conversationId", conversationId.ToString() } }.ToString(), Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveProgressBar() { Title = "Weekly playlist", Value = new BindableProgressBarValue("progressValue"), ValueStringOverride = new BindableString("progressValueString"), Status = new BindableString("progressStatus") }, new AdaptiveText() { Text = content }, new AdaptiveImage() { // Non-Desktop Bridge apps cannot use HTTP images, so // we download and reference the image locally Source = await DownloadImageToDisk(image) } }, AppLogoOverride = new ToastGenericAppLogo() { Source = await DownloadImageToDisk("https://unsplash.it/64?image=1005"), HintCrop = ToastGenericAppLogoCrop.Circle } } }, Actions = new ToastActionsCustom() { Inputs = { new ToastTextBox("tbReply") { PlaceholderContent = "Type a response" } }, Buttons = { // Note that there's no reason to specify background activation, since our COM // activator decides whether to process in background or launch foreground window new ToastButton("Reply", new QueryString() { { "action", "reply" }, { "conversationId", conversationId.ToString() } }.ToString()), new ToastButton("Like", new QueryString() { { "action", "like" }, { "conversationId", conversationId.ToString() } }.ToString()), new ToastButton("View", new QueryString() { { "action", "viewImage" }, { "imageUrl", image } }.ToString()) } } }; // Make sure to use Windows.Data.Xml.Dom var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification var toast = new ToastNotification(doc); toast.Tag = tag; toast.Group = group; toast.Data = new NotificationData(); toast.Data.Values["progressValue"] = "0.6"; toast.Data.Values["progressValueString"] = "15/26 songs"; toast.Data.Values["progressStatus"] = "Downloading..."; // Provide sequence number to prevent out-of-order updates, or assign 0 to indicate "always update" toast.Data.SequenceNumber = 0; ; // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); Task.Run(UpdateProgress); }
public void ShowToastNotification(ToastNotification toastNotification) { DesktopNotificationManagerCompat.CreateToastNotifier().Show(toastNotification); }
public static async void ShowNotification(string title, string message, string URL, string commentID, string id, string name, string writer, string identity, string thumbnailURL) { if (MainWindow.IsDND != true) { if (Environment.OSVersion.Version.Major == 10) { try { var Visual = new Microsoft.Toolkit.Uwp.Notifications.ToastVisual() { BindingGeneric = new Microsoft.Toolkit.Uwp.Notifications.ToastBindingGeneric() { Children = { new Microsoft.Toolkit.Uwp.Notifications.AdaptiveText() { Text = title }, new Microsoft.Toolkit.Uwp.Notifications.AdaptiveText() { Text = message } } } }; try { bool isThumbnailReplaced = false; string text = URL.Split(new string[] { "!" }, StringSplitOptions.None)[1]; string activityID = text.Split(new string[] { "activities/" }, StringSplitOptions.None)[1]; var post = await KakaoRequestClass.GetPost(activityID); if (commentID != null) { foreach (var comment in post.comments) { if (comment.id.Equals(commentID)) { thumbnailURL = comment.decorators?[0]?.media?.url; if (thumbnailURL != null) { isThumbnailReplaced = true; } break; } } } if (!isThumbnailReplaced) { if (post.@object != null) { if ([email protected]_type?.Equals("video") == true) { thumbnailURL = [email protected][0]?.preview_url_hq; } else { thumbnailURL = [email protected]?[0]?.url; } } else { if (post.media_type?.Equals("video") == true) { thumbnailURL = post.media[0]?.preview_url_hq; } else { thumbnailURL = post.media?[0]?.url; } } } if (thumbnailURL != null) { Visual.BindingGeneric.HeroImage = new Microsoft.Toolkit.Uwp.Notifications.ToastGenericHeroImage() { Source = thumbnailURL, }; } } catch (Exception) { } Microsoft.Toolkit.Uwp.Notifications.ToastActionsCustom Action; if (URL == null) { Action = new Microsoft.Toolkit.Uwp.Notifications.ToastActionsCustom(); } else { if (commentID != null) { Action = new Microsoft.Toolkit.Uwp.Notifications.ToastActionsCustom() { Inputs = { new Microsoft.Toolkit.Uwp.Notifications.ToastTextBox("tbReply") { PlaceholderContent = "답장 작성하기", }, }, Buttons = { new Microsoft.Toolkit.Uwp.Notifications.ToastButton("보내기", URL + "REPLY!@#$%" + "R!@=!!" + id + "R!@=!!" + name + "R!@=!!" + writer + "R!@=!!" + identity) { ActivationType = Microsoft.Toolkit.Uwp.Notifications.ToastActivationType.Background, TextBoxId = "tbReply" }, new Microsoft.Toolkit.Uwp.Notifications.ToastButton("열기", URL), new Microsoft.Toolkit.Uwp.Notifications.ToastButton("좋아요", URL + "LIKE!@#$%" + commentID), }, }; } else { Action = new Microsoft.Toolkit.Uwp.Notifications.ToastActionsCustom() { Buttons = { new Microsoft.Toolkit.Uwp.Notifications.ToastButton("열기", URL) } }; } } var toastContent = new Microsoft.Toolkit.Uwp.Notifications.ToastContent() { Visual = Visual, Actions = Action, }; var toastXml = new Windows.Data.Xml.Dom.XmlDocument(); toastXml.LoadXml(toastContent.GetContent()); var toast = new Windows.UI.Notifications.ToastNotification(toastXml); //toast.Activated += (s, e) => //{ // KSPNotificationActivator.ActivateHandler(URL, null); //}; toast.ExpirationTime = DateTimeOffset.MaxValue; DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); } catch (Exception) { } } } }
/// <summary> /// Show toast notification. /// </summary> /// <param name="arguments">Notification arguments object.</param> /// <returns>Toast notification object.</returns> public static async Task <ToastNotification> ShowToast(NotificationArguments arguments) { //Set the toast visual var visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = arguments.Title }, new AdaptiveText() { Text = arguments.Message } } } }; //Set the attribution text if (!string.IsNullOrWhiteSpace(arguments.AttributionText)) { visual.BindingGeneric.Attribution = new ToastGenericAttributionText() { Text = arguments.AttributionText }; } //Set the logo override var imagePath = Globals.GetImageOrDefault(arguments.PicturePath); var isInternetImage = IsInternetImage(imagePath); var imageSource = isInternetImage ? await DownloadImageToDisk(imagePath) : imagePath; visual.BindingGeneric.AppLogoOverride = new ToastGenericAppLogo() { Source = imageSource, HintCrop = ToastGenericAppLogoCrop.Circle }; //Set a background image if (!string.IsNullOrWhiteSpace(arguments.Image)) { isInternetImage = IsInternetImage(arguments.Image); imageSource = isInternetImage ? await DownloadImageToDisk(arguments.Image) : arguments.Image; visual.BindingGeneric.Children.Add(new AdaptiveImage() { Source = imageSource }); } // Construct the actions for the toast (inputs and buttons) var actions = new ToastActionsCustom(); // Add any inputs if (arguments.Inputs != null) { foreach (var input in arguments.Inputs) { var textBox = new ToastTextBox(input.Id) { PlaceholderContent = input.PlaceHolderText }; if (!string.IsNullOrWhiteSpace(input.Title)) { textBox.Title = input.Title; } actions.Inputs.Add(textBox); } } // Add any buttons if (arguments.Buttons != null) { foreach (var button in arguments.Buttons) { actions.Buttons.Add(new ToastButton(button.Text, button.Arguments)); //Background activation is not needed the COM activator decides whether //to process in background or launch foreground window //actions.Buttons.Add(new ToastButton(button.Text, button.Arguments) //{ // ActivationType = ToastActivationType.Background //}); } } //Set the audio ToastAudio audio = null; if (!string.IsNullOrWhiteSpace(arguments.WindowsSound) || !string.IsNullOrWhiteSpace(arguments.SoundPath)) { string sound; if (string.IsNullOrWhiteSpace(arguments.WindowsSound)) { sound = "file:///" + arguments.SoundPath; } else { sound = $"ms-winsoundevent:{arguments.WindowsSound}"; } audio = new ToastAudio() { Src = new Uri(sound), Loop = bool.Parse(arguments.Loop), Silent = arguments.Silent }; } // Construct the toast content var toastContent = new ToastContent() { Visual = visual, Actions = actions, Audio = audio }; // Create notification var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(toastContent.GetContent()); var toast = new ToastNotification(xmlDocument); // Set the expiration time if (!string.IsNullOrWhiteSpace(arguments.Duration)) { switch (arguments.Duration) { case "short": toast.ExpirationTime = DateTime.Now.AddSeconds(5); break; case "long": toast.ExpirationTime = DateTime.Now.AddSeconds(25); break; } } //Add event handlers var events = new NotificationEvents(); toast.Activated += events.Activated; toast.Dismissed += events.Dismissed; toast.Failed += events.Failed; //Show notification DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); return(toast); }
private void BtnTestNotification_Click(object sender, EventArgs e) { ToastHandler th = new ToastHandler(); DesktopNotificationManagerCompat.CreateToastNotifier().Show(th.BuildToast("hello dork")); }
private void OnTimedEvent(Object source, ElapsedEventArgs e) { //notification = new NotifyIcon() //{ // Visible = true, // //Icon = System.Drawing.SystemIcons.Information, // Icon = Icon.FromHandle(Resource1.smiley_face_1.GetHicon()), // // optional - BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info, // // optional - BalloonTipTitle = "My Title", // BalloonTipText = "my long description...7", //}; //notification.ShowBalloonTip(1000); // string toastXmlString = //$@"<toast><visual> // <binding template='ToastImageAndText01'> // <image src = Res></image> // <text>7</text> // </binding> // </visual></toast>"; // var xmlDoc = new XmlDocument(); // xmlDoc.LoadXml(toastXmlString); // var toastNotification = new ToastNotification(xmlDoc); //toastNotifier = ToastNotificationManager.CreateToastNotifier("Microsoft.Samples.DesktopToastsSample"); //toastNotification.Failed += (a, b) => { textBox1.Text = "toast failed"; }; //toastNotifier.Show(toastNotification); //this.textBox1.Text = i.ToString(); //i++; //popupNotifier = new PopupNotifier(); //popupNotifier.Image = Resource1.smiley_face_1; //popupNotifier.TitleText = "title"; //popupNotifier.ContentText = "content"; //popupNotifier.Popup(); var imageloc = new System.Uri(this.image_base_dir + "/" + this.image_arr[counter % 5]); ToastContent toastContent = new ToastContentBuilder() .AddToastActivationInfo("action=viewConversation&conversationId=5", ToastActivationType.Foreground) .AddText(this.toast_text_arr[this.counter % 5]).AddInlineImage(imageloc).GetToastContent(); counter++; // And create the toast notification var toast = new ToastNotification(toastContent.GetXml()); //toast.Activated += showVideo(null, null); //toast.Activated += ToastNotification_Activated; // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
private void ButtonPopToast_Click(object sender, RoutedEventArgs e) { string title = "Andrew sent you a picture"; string content = "Check this out, Happy Canyon in Utah!"; string image = "https://picsum.photos/360/202?image=883"; int conversationId = 5; // Construct the toast content ToastContent toastContent = new ToastContent() { // Arguments when the user taps body of toast Launch = new QueryString() { { "action", "viewConversation" }, { "conversationId", conversationId.ToString() } }.ToString(), Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = content } } } }, Actions = new ToastActionsCustom() { Inputs = { new ToastTextBox("tbReply") { PlaceholderContent = "Type a response" } }, Buttons = { new ToastButton("Reply", new QueryString() { { "action", "reply" }, { "conversationId", conversationId.ToString() } }.ToString()) { ActivationType = ToastActivationType.Background }, new ToastButton("Like", new QueryString() { { "action", "like" }, { "conversationId", conversationId.ToString() } }.ToString()) { ActivationType = ToastActivationType.Background }, new ToastButton("View", new QueryString() { { "action", "viewImage" }, { "imageUrl", image } }.ToString()) } } }; Clipboard.SetText(toastContent.GetContent()); var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification var toast = new ToastNotification(doc); // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }