private static ScheduledToastNotification GenerateAlarmNotification(MyRemind remind) { ToastContent content = new ToastContent() { Scenario = ToastScenario.Alarm, Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = $"提醒: {remind.Title}" }, new AdaptiveText() { Text = remind.Content } } } }, Actions = new ToastActionsSnoozeAndDismiss()//自动创建一个自动本地化的有延迟提醒时间间隔,贪睡和取消的按钮,贪睡时间由系统自动处理 }; return new ScheduledToastNotification(content.GetXml(), remind.time) { Tag = GetTag(remind) }; }
public static void ToastImageAndText04(string title, string t1, string t2, string t3, string imgsrc, string toastId, string imgalt = "", string uri = "") { var toastContent = new ToastContent(); if (!string.IsNullOrEmpty(uri)) { toastContent.Launch = uri; } toastContent.Visual = new ToastVisual() { TitleText = new ToastText() { Text = title }, BodyTextLine1 = new ToastText() { Text = t1 }, BodyTextLine2 = new ToastText() { Text = t3 }, }; if (imgsrc != null) { toastContent.Visual.InlineImages.Add(new ToastImage() { Source = new ToastImageSource(imgsrc), }); } toastContent.Audio = new ToastAudio() { Silent = true, }; ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastContent.GetXml())); }
private async void loadButton_Click(object sender, RoutedEventArgs e) { var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; openPicker.FileTypeFilter.Add(".eqn"); openPicker.FileTypeFilter.Add(".txt"); Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { Stream stream = await file.OpenStreamForReadAsync(); StreamReader streamreader = new StreamReader(stream); textBox.Text = streamreader.ReadToEnd(); if (showNotifications) { var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Easy Quick Note" }, new AdaptiveText() { Text = "Opened note." }, new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = "Note name: " + file.Name }, new AdaptiveText() { Text = "Note file path: " + file.Path } } } } } } } } }; // Create the toast notification var toastNotif = new ToastNotification(toastContent.GetXml()); // And send the notification ToastNotificationManager.CreateToastNotifier().Show(toastNotif); } } }
private void ShowTileToast(ArcadeTileData data, string title, bool isLarge = false) { var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title, HintMaxLines = 1, }, new AdaptiveText() { Text = data.Name, }, new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = "Players", HintStyle = AdaptiveTextStyle.Body, }, }, }, new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = data.Players, HintStyle = AdaptiveTextStyle.CaptionSubtle, HintAlign = AdaptiveTextAlign.Right, } }, }, }, }, }, HeroImage = new ToastGenericHeroImage() { Source = data.Image, }, }, }, }; var notification = new ToastNotification(toastContent.GetXml()); ToastNotificationManager.CreateToastNotifier().Show(notification); }
private void ButtonSendToastNotification_Click(object sender, RoutedEventArgs e) { ToastContent content = new ToastContent() { Launch = "lei", Visual = new ToastVisual() { TitleText = new ToastText() { Text = "New message from Lei" }, BodyTextLine1 = new ToastText() { Text = "NotificationsExtensions is great!" }, AppLogoOverride = new ToastAppLogo() { Crop = ToastImageCrop.Circle, Source = new ToastImageSource("http://messageme.com/lei/profile.jpg") } }, Actions = new ToastActionsCustom() { Inputs = { new ToastTextBox("tbReply") { PlaceholderContent = "Type a response" } }, Buttons = { new ToastButton("Reply", "reply") { ActivationType = ToastActivationType.Background, }, new ToastButton("", "dismiss") { ActivationType = ToastActivationType.System, } } }, Audio = new ToastAudio() { Src = new Uri("ms-winsoundevent:Notification.IM") } }; DataPackage dp = new DataPackage(); dp.SetText(content.GetContent()); Clipboard.SetContent(dp); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml())); }
public string GetInteractiveToastXml() { var toastVisual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = _toastModel.Title }, // Title new AdaptiveText { Text = _toastModel.Body }, // Body }, AppLogoOverride = new ToastGenericAppLogo { Source = _toastModel.ImagePath, AlternateText = "Logo" } } }; var toastAction = new ToastActionsCustom { //Inputs = //{ // new ToastTextBox(id: MessageId) { PlaceholderContent = "Input a message" } //}, 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("Open", new QueryString() { { "action", "open" } }.ToString()), new ToastButton("Close", new QueryString() { { "action", "dismiss" } }.ToString()), } }; var toastAudio = new ToastAudio(); if (!_toastModel.Silent) { toastAudio = new ToastAudio { Loop = true, Src = new Uri("ms-winsoundevent:Notification.Looping.Alarm4") }; } var toastContent = new ToastContent { Visual = toastVisual, Actions = toastAction, Duration = ToastDuration.Long, Audio = toastAudio }; return(toastContent.GetContent()); }
public override Task Send(Notification notification) { if (notification.Id == null) { notification.Id = this.GetNotificationId(); } var toastContent = new ToastContent { Launch = this.ToQueryString(notification.Metadata), Visual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = notification.Title }, new AdaptiveText { Text = notification.Message } } } } }; if (string.IsNullOrWhiteSpace(notification.Sound)) { notification.Sound = Notification.DefaultSound; } if (!String.IsNullOrWhiteSpace(notification.Sound) && this.IsAudioSupported) { if (!notification.Sound.StartsWith("ms-appx:")) { notification.Sound = $"ms-appx:///Assets/Audio/{notification.Sound}.m4a"; } toastContent.Audio = new ToastAudio { Src = new Uri(notification.Sound) }; } if (notification.Date == null && notification.When == null) { var toast = new ToastNotification(toastContent.GetXml()); this.toastNotifier.Show(toast); } else { var schedule = new ScheduledToastNotification(toastContent.GetXml(), notification.SendTime) { Id = notification.Id.Value.ToString() }; this.toastNotifier.AddToSchedule(schedule); } return(Task.CompletedTask); }
private static ToastContent getToastContentWithoutPlay(Vocabulary _item) { ToastContent content = new ToastContent() { Launch = "vocabulary-reminder", Audio = new ToastAudio() { Silent = true }, Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = _item.Word, HintMaxLines = 1 }, new AdaptiveText() { Text = _item.Ipa, }, new AdaptiveText() { Text = _item.Translate } }, HeroImage = new ToastGenericHeroImage() { Source = "https://picsum.photos/364/180?image=1043" }, } }, Scenario = ToastScenario.Reminder, Actions = new ToastActionsCustom() { Buttons = { new ToastButton("Next", new QueryString() { { "WordId", _item.Id.ToString() }, { "action", "next" }, }.ToString()) { ActivationType = ToastActivationType.Background, ActivationOptions = new ToastActivationOptions() { AfterActivationBehavior = ToastAfterActivationBehavior.PendingUpdate } }, new ToastButton("View", new QueryString() { { "action", "view" }, { "url", viewDicOnlineUrl + _item.Word } }.ToString()), new ToastButton("Skip", "dismiss") { ActivationType = ToastActivationType.Background }, } }, }; return(content); }
public void ShowNotification() { // https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/07/08/quickstart-sending-a-local-toast-notification-and-handling-activations-from-it-windows-10/; // In a real app, these would be initialized with actual data string title = "Smart City"; string content = "Nouveaux travaux signalés!"; string image = "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f1/France_road_sign_AK5.svg/200px-France_road_sign_AK5.svg.png"; string logo = "ms-appdata:///Assets/Travaux.png"; // Construct the visuals of the toast ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = content }, new AdaptiveImage() { Source = image } }, AppLogoOverride = new ToastGenericAppLogo() { Source = logo, HintCrop = ToastGenericAppLogoCrop.Circle } } }; // Now we can construct the final toast content ToastContent toastContent = new ToastContent() { Visual = visual, //Actions = actions, // Arguments when the user taps body of toast // Launch = new QueryString() //{ // { "action", "viewConversation" }, // { "conversationId", conversationId.ToString() } //}.ToString() }; // And create the toast notification var toast = new ToastNotification(toastContent.GetXml()); toast.ExpirationTime = DateTime.Now.AddMinutes(2); ToastNotificationManager.CreateToastNotifier().Show(toast); }
public static ToastNotification ConvertToast(MyToast myToast) { Dictionary <int, Models.ToastVisual> visualDict = new Dictionary <int, Models.ToastVisual>(); Dictionary <int, QueryString> actionDict = new Dictionary <int, QueryString>(); ToastActionsCustom actions = new ToastActionsCustom(); QueryString launch = new QueryString(); Microsoft.Toolkit.Uwp.Notifications.ToastVisual visual = new Microsoft.Toolkit.Uwp.Notifications.ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "" } } } }; foreach (Models.ToastVisual nowVisual in myToast.VisualList) { switch (nowVisual.Visual) { case VisualType.TITLE: visual.BindingGeneric.Children[0] = new AdaptiveText() { Text = nowVisual.ToString() }; break; case VisualType.DETAIL: visual.BindingGeneric.Children.Add(new AdaptiveText() { Text = nowVisual.ToString() }); break; case VisualType.MAIN_IMG: visual.BindingGeneric.Children.Add(new AdaptiveImage() { Source = nowVisual.ToString() }); break; case VisualType.LOGO_IMG: visual.BindingGeneric.AppLogoOverride = new ToastGenericAppLogo() { Source = nowVisual.ToString(), HintCrop = ToastGenericAppLogoCrop.Circle }; break; case VisualType.BUTTON1: case VisualType.BUTTON2: case VisualType.BUTTON3: int index = (int)nowVisual.Visual - (int)VisualType.BUTTON1; if (!visualDict.ContainsKey(index)) { visualDict.Add(index, nowVisual); } else { visualDict[index] = nowVisual; } break; } } foreach (ToastAction nowAction in myToast.ActionList) { switch (nowAction.When) { case WhenType.BODY: launch.Add(new QueryString() { { "action", ((int)nowAction.ActionType).ToString() }, { "id", nowAction.ToString() }, { "folder", nowAction.Folder } }.ToString()); break; case WhenType.BUTTON1: case WhenType.BUTTON2: case WhenType.BUTTON3: int when = (int)nowAction.When - (int)WhenType.BUTTON1; if (!actionDict.ContainsKey(when)) { actionDict.Add(when, new QueryString() { { "action", ((int)nowAction.ActionType).ToString() }, { "id", nowAction.ToString() }, { "folder", nowAction.Folder } }); } else { actionDict[when].Add("action", ((int)nowAction.ActionType).ToString()); actionDict[when].Add("id", nowAction.ToString()); actionDict[when].Add("folder", nowAction.Folder); } break; } } /*Add button*/ foreach (var nowVisual in visualDict.OrderBy(x => x.Key)) { actions.Buttons.Add( new ToastButton(nowVisual.Value.ToString(), actionDict.ContainsKey(nowVisual.Key) == true ? actionDict[nowVisual.Key].ToString() : "") ); } ToastContent toastContent = new ToastContent() { Visual = visual, Actions = actions, Launch = launch.ToString(), }; // 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); toast.ExpirationTime = DateTime.Now.AddDays(3); return(toast); }
/// <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 SaveChanges_Click(object sender, RoutedEventArgs e) { var parameter1 = new Reminder(); if (String.IsNullOrWhiteSpace(ReminderNameBox.Text)) { parameter1.ReminderName = "Untitled Reminder"; } else { parameter1.ReminderName = ReminderNameBox.Text; } if (String.IsNullOrWhiteSpace(LocationBox.Text)) { parameter1.LocationName = "Location: None"; } else { parameter1.LocationName = LocationBox.Text; } if (String.IsNullOrWhiteSpace(EmailBox.Text)) { parameter1.EmailName = "Email: None"; } else { parameter1.EmailName = EmailBox.Text; } if (String.IsNullOrWhiteSpace(NotesBox.Text)) { parameter1.ReminderNotes = "Notes: None"; } else { parameter1.ReminderNotes = NotesBox.Text; } if (String.IsNullOrWhiteSpace(LinkBox.Text)) { parameter1.ReminderLinks = "Links: None"; } else { parameter1.ReminderLinks = LinkBox.Text; } var reminderDate = ReminderDatePicker.Date; if (reminderDate.HasValue) { DateTime date1 = reminderDate.Value.DateTime; var notificationDate = ReminderDatePicker.Date.Value.DateTime; parameter1.NotificationTime = notificationDate; var formattedDate = date1.ToString("MM/dd/yyyy"); parameter1.ReminderDate = formattedDate; } else { parameter1.ReminderDate = "Date: None"; parameter1.NotificationTime = DateTime.Now; } var reminderTimeHours = ReminderTimePicker.Time.Hours; var reminderTimeMinutes = ReminderTimePicker.Time.Minutes; string amPm; if (reminderTimeHours > 12) { reminderTimeHours -= 12; amPm = "PM"; } else { amPm = "AM"; } string formattedHours; if (reminderTimeHours < 10) { formattedHours = reminderTimeHours.ToString(); formattedHours = "0" + formattedHours; } else { formattedHours = reminderTimeHours.ToString(); } string formattedMinutes; if (reminderTimeMinutes < 10) { formattedMinutes = reminderTimeMinutes.ToString(); formattedMinutes = "0" + formattedMinutes; } else { formattedMinutes = reminderTimeMinutes.ToString(); } string timeString; if (reminderTimeHours == 0 && reminderTimeMinutes == 0) { timeString = "Time: None"; } else { timeString = formattedHours + ":" + formattedMinutes + " " + amPm; } parameter1.ReminderTime = timeString; int reminderComboBox; if (NotificationComboBox.SelectedValue != null) { switch (NotificationComboBox.SelectedValue.ToString()) { case "5 Minutes Before": reminderComboBox = 5; break; case "10 Minutes Before": reminderComboBox = 10; break; case "15 Minutes Before": reminderComboBox = 15; break; case "30 Minutes Before": reminderComboBox = 30; break; case "1 Hour Before": reminderComboBox = 60; break; case "5 Hours Before": reminderComboBox = 300; break; default: reminderComboBox = 0; break; } } else { reminderComboBox = 0; } parameter1.ReminderNotification = reminderComboBox; ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Reminder" }, new AdaptiveText() { Text = "Body" }, new AdaptiveText() { Text = "End Reminder" } } } }; ToastContent toastContent = new ToastContent() { Visual = visual }; var toast = new ToastNotification(toastContent.GetXml()); //ToastNotificationManager.CreateToastNotifier().Show(toast); toast.ExpirationTime = DateTime.Now.AddSeconds(5); //var toast = new Windows.UI.Notifications.ScheduledToastNotification(toastContent.GetXml, ReminderDatePicker.Date.Value.DateTime); if (ReminderDatePicker.Date.HasValue) { if (ReminderDatePicker.Date.Value.Date == DateTime.Today.Date) { if (ReminderTimePicker.Time.Hours < DateTime.Now.Hour) { ToastNotificationManager.CreateToastNotifier().Show(toast); } else { //var timeSpan = new TimeSpan(0, ReminderTimePicker.Time.Hours - DateTime.Now.Hour, ReminderTimePicker.Time.Minutes - DateTime.Now.Minute, 0); var midnight = DateTime.Now; var minutesCounter = ReminderTimePicker.Time.Minutes - DateTime.Now.Minute; var hoursCounter = ReminderTimePicker.Time.Hours - DateTime.Now.Hour; var intMinutesCounter = Convert.ToInt32(minutesCounter); var intHoursCounter = Convert.ToInt32(hoursCounter); var timeSpan = new TimeSpan(0, intHoursCounter, intMinutesCounter, 0); DateTimeOffset scheduledTime = midnight + timeSpan; var toast1 = new ScheduledToastNotification(toastContent.GetXml(), scheduledTime); //ToastNotificationManager.CreateToastNotifier().Show(toast); ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast1); } } } //var toast = new ScheduledToastNotification(toastContent.GetXml(), ReminderDatePicker.Date.Value.DateTime); //ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast); this.Frame.Navigate(typeof(MainPage), parameter1); }
/// <summary> /// Simple method to show a basic toast with a message. /// </summary> /// <param name="message"></param> private void SendToast(string message) { ToastContent content = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Background Task Completed" }, new AdaptiveText() { Text = message } } } } }; ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml())); }
public void AddNotification(LaunchData launchData, NotificationType type) { if (launchData?.Launch == null) return; var deliverytime = TimeConverter.DetermineTimeSettings(launchData.Launch.Net, true) .AddMinutes(-LaunchPal.App.Settings.NotifyBeforeLaunch.ToIntValue()); if (deliverytime < DateTime.Now) { return; } switch (type) { case NotificationType.NextLaunch: if (!LaunchPal.App.Settings.LaunchInProgressNotifications) return; break; case NotificationType.TrackedLaunch: if (!LaunchPal.App.Settings.TrackedLaunchNotifications) return; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } var groupName = GetGroupNameFromNotificationType(type); ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Launch Alert!" }, new AdaptiveText() { Text = $"{launchData?.Launch?.Name} is about to launch." }, new AdaptiveText() { Text = $"Time: {TimeConverter.SetStringTimeFormat(launchData.Launch.Net, LaunchPal.App.Settings.UseLocalTime).Replace(" Local", "")}" } }, AppLogoOverride = new ToastGenericAppLogo() { Source = "Assets/BadgeLogo.scale-200.png", HintCrop = ToastGenericAppLogoCrop.Default } } }; // Now we can construct the final toast content ToastContent toastContent = new ToastContent() { Visual = visual, // Arguments when the user taps body of toast Launch = new QueryString() { { "action", "viewLaunch" }, { "LaunchId", launchData?.Launch?.Id.ToString() } }.ToString(), Actions = new ToastActionsCustom() { Inputs = { new ToastSelectionBox("snoozeTime") { DefaultSelectionBoxItemId = "15", Items = { new ToastSelectionBoxItem("5", "5 minutes"), new ToastSelectionBoxItem("15", "15 minutes"), new ToastSelectionBoxItem("30", "30 minutes"), new ToastSelectionBoxItem("45", "45 minutes"), new ToastSelectionBoxItem("60", "1 hour") } } }, Buttons = { new ToastButtonSnooze() { SelectionBoxId = "snoozeTime" }, new ToastButtonDismiss() } } }; // And create the toast notification var scheduleToast = new ScheduledToastNotification(toastContent.GetXml(), deliverytime) { Id = launchData?.Launch?.Id.ToString() ?? "0", Tag = launchData?.Launch?.Id.ToString() ?? "0", Group = groupName, NotificationMirroring = NotificationMirroring.Allowed, }; ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduleToast); }
private static void sendToast(IReadOnlyDictionary <string, double> data) { var format = default(Opportunity.ResourceGenerator.FormattableResourceString); switch (data.Count) { case 1: format = Strings.Resources.DawnOfDayToast.Content1(); break; case 2: format = Strings.Resources.DawnOfDayToast.Content2(); break; case 3: format = Strings.Resources.DawnOfDayToast.Content3(); break; case 4: format = Strings.Resources.DawnOfDayToast.Content4(); break; default: return; } var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = Strings.Resources.DawnOfDayToast.Title, }, new AdaptiveText() { Text = string.Format(format.FormatString, data.Keys.Select(getStr).ToArray()), } } } } }; string getStr(string key) { data.TryGetValue(key, out var r); var kstr = r % 1 == 0 ? r.ToString("N0") : r.ToString("N"); switch (key) { case "EXP": return(Strings.Resources.DawnOfDayToast.RewardExp(kstr)); case "Credits": return(Strings.Resources.DawnOfDayToast.RewardCredits(kstr)); case "GP": return(Strings.Resources.DawnOfDayToast.RewardGp(kstr)); case "Hath": return(Strings.Resources.DawnOfDayToast.RewardHath(kstr)); default: Debug.Assert(false, "Invalid key!"); break; } return(""); } var toastNotif = new ToastNotification(toastContent.GetXml()) { Group = "DawnOfDay", NotificationMirroring = NotificationMirroring.Allowed, }; ToastNotificationManager.CreateToastNotifier().Show(toastNotif); }
public static void Notifications_Tocast() { string title = "查看今天的新文件"; string content = "发现新文件"; string view = "查看"; string cancel = "取消"; switch (UserSettings.PrimaryLanguage) { case "en-US": { title = "Today's New Files"; content = "Find New Files"; view = "View"; cancel = "Cancel"; break; } case "ja": { title = "今日の新しいファイル"; content = "新しいファイルを発見"; view = "確認"; cancel = "キャッセル"; break; } case "zh-Hans-CN": { title = "查看今天的新文件"; content = "发现新文件"; view = "查看"; cancel = "取消"; break; } default: break; } //string image = "https://picsum.photos/360/202?image=883"; //string image = "Resources/BF942982C59CEBF2640D14CD6F9420CB.png"; var image = "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE3sKm8?ver=08d4&q=90&m=6&h=201&w=358&b=%23FFFFFFFF&l=f&o=t&aim=true"; string logo = "Resources/BF942982C59CEBF2640D14CD6F9420CB.png"; // Construct the visuals of the toast ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = content }, new AdaptiveImage() { Source = image } }, AppLogoOverride = new ToastGenericAppLogo() { Source = logo, HintCrop = ToastGenericAppLogoCrop.Circle } } }; //// // In a real app, these would be initialized with actual data int conversationId = 384928; // Construct the actions for the toast (inputs and buttons) ToastActionsCustom actions = new ToastActionsCustom() { Inputs = { }, Buttons = { new ToastButton(view, new QueryString() { { "action", "viewImage"}, { "imageUrl", image } }.ToString()), new ToastButton(cancel, new QueryString() { { "action", "cancel" }, { "conversationId", conversationId.ToString() } }.ToString()) { ActivationType = ToastActivationType.Background } } }; //// ToastContent toastContent = new ToastContent() { Visual = visual, Actions = actions, // Arguments when the user taps body of toast Launch = new QueryString() { { "action", "viewConversation" }, { "conversationId", conversationId.ToString() } }.ToString() }; // And create the toast notification var toast = new ToastNotification(toastContent.GetXml()); toast.ExpirationTime = DateTime.Now.AddDays(1); // toast.Tag = "18365"; toast.Group = "wallPosts"; // ToastNotificationManager.CreateToastNotifier().Show(toast); }
private void ButtonSendToast_Click(object sender, RoutedEventArgs e) { // In a real app, these would be initialized with actual data string title = "Andrew sent you a picture"; 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 logo = "ms-appdata:///local/Andrew.jpg"; int conversationId = 384928; // Construct the visuals of the toast ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = content }, new AdaptiveImage() { Source = image } }, AppLogoOverride = new ToastGenericAppLogo() { Source = logo, HintCrop = ToastGenericAppLogoCrop.Circle } } }; // Construct the actions for the toast (inputs and buttons) ToastActionsCustom 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, ImageUri = "Assets/Reply.png", // Reference the text box's ID in order to // place this button next to the text box TextBoxId = "tbReply" }, new ToastButton("Like", new QueryString() { { "action", "like" }, { "conversationId", conversationId.ToString() } }.ToString()) { ActivationType = ToastActivationType.Background }, new ToastButton("View", new QueryString() { { "action", "viewImage" }, { "imageUrl", image } }.ToString()) } }; // Now we can construct the final toast content ToastContent toastContent = new ToastContent() { Visual = visual, Actions = actions, // Arguments when the user taps body of toast Launch = new QueryString() { { "action", "viewConversation" }, { "conversationId", conversationId.ToString() } }.ToString() }; // And create the toast notification ToastNotification notification = new ToastNotification(toastContent.GetXml()); // And then send the toast ToastNotificationManager.CreateToastNotifier().Show(notification); }
public static ToastNotification GenerateProgressToast(PackageBase package) { if (!OperatingSystem.IsWindowsVersionAtLeast(10, 0, 18362)) { return(null); } var visualBinding = new ToastBindingGeneric { Children = { new AdaptiveText { Text = new BindableString("progressTitle") }, new AdaptiveProgressBar { Value = new BindableProgressBarValue("progressValue"), Title = new BindableString("progressVersion"), Status = new BindableString("progressStatus") } }, }; if (package.GetAppIcon().Result is SDK.Images.FileImage image && !image.Uri.IsFile) { visualBinding.AppLogoOverride = new ToastGenericAppLogo { Source = image.Url }; } var content = new ToastContent { Visual = new ToastVisual { BindingGeneric = visualBinding }, // TODO: Add cancel and pause functionality //Actions = new ToastActionsCustom() //{ // Buttons = // { // new ToastButton("Pause", $"action=pauseDownload&packageName={package.PackageMoniker}") // { // ActivationType = ToastActivationType.Background // }, // new ToastButton("Cancel", $"action=cancelDownload&packageName={package.PackageMoniker}") // { // ActivationType = ToastActivationType.Background // } // } //}, Launch = $"package/{package.Urn}", }; var notif = new ToastNotification(content.GetXml()); notif.Data = new NotificationData(new Dictionary <string, string>() { { "progressTitle", package.Title }, { "progressVersion", package.Version?.ToString() ?? string.Empty }, { "progressStatus", "Downloading..." } }); return(notif); }
private static void SendUpdatableToastWithProgressForTranscode(StorageFile SourceFile, StorageFile DestinationFile) { try { string Tag = "TranscodeNotification"; ToastContent content = new ToastContent() { Launch = "Transcode", Scenario = ToastScenario.Reminder, Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = $"{Globalization.GetString("Transcode_Toast_Title")} {SourceFile.Name}" }, new AdaptiveProgressBar() { Title = SourceFile.FileType.Substring(1).ToUpper() + " ⋙⋙⋙⋙ " + DestinationFile.FileType.Substring(1).ToUpper(), Value = new BindableProgressBarValue("ProgressValue"), ValueStringOverride = new BindableString("ProgressValueString"), Status = new BindableString("ProgressStatus") } } } } }; NotificationData Data = new NotificationData { SequenceNumber = 0 }; Data.Values["ProgressValue"] = "0"; Data.Values["ProgressValueString"] = "0%"; Data.Values["ProgressStatus"] = Globalization.GetString("Toast_ClickToCancel_Text"); ToastNotification Toast = new ToastNotification(content.GetXml()) { Tag = Tag, Data = Data }; Toast.Activated += (s, e) => { if (s.Tag == "TranscodeNotification") { AVTranscodeCancellation?.Cancel(); } }; ToastNotificationManager.CreateToastNotifier().Show(Toast); } catch (Exception ex) { LogTracer.Log(ex, "Toast notification could not be sent"); } }
private static ToastContent getToastContent(Vocabulary _item) { string _Ipa = _item.Ipa; if (_item.Ipa != _item.Ipa2) { _Ipa = _item.Ipa + " " + _item.Ipa2; } ToastContent content = new ToastContent() { Duration = ToastDuration.Long, Launch = "vocabulary-reminder", Audio = new ToastAudio() { Silent = true }, Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Attribution = new ToastGenericAttributionText() { Text = _item.Type }, Children = { new AdaptiveText() { Text = _item.Define, }, new AdaptiveText() { Text = _item.Example, }, new AdaptiveText() { Text = _item.Example2, }, new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = _item.Word + " " + _Ipa, HintStyle = AdaptiveTextStyle.Subtitle, }, new AdaptiveText() { Text = _item.Translate, HintStyle = AdaptiveTextStyle.Base, }, new AdaptiveText() { Text = _item.Related, HintStyle = AdaptiveTextStyle.CaptionSubtle } } }, } } }, HeroImage = new ToastGenericHeroImage() { Source = "https://picsum.photos/364/180?image=1043" }, } }, Scenario = ToastScenario.Reminder, Actions = new ToastActionsCustom() { ContextMenuItems = { new ToastContextMenuItem("Reload", "action=reload&WordId=" + _item.Id.ToString()) }, Buttons = { new ToastButton("\u25B6", new QueryString() { { "action", "play" }, { "WordId", _item.Id.ToString() }, { "PlayId", "1" }, { "PlayUrl", _item.PlayURL }, }.ToString()) { ActivationType = ToastActivationType.Background, ActivationOptions = new ToastActivationOptions() { AfterActivationBehavior = ToastAfterActivationBehavior.PendingUpdate } }, new ToastButton("\u25B7", new QueryString() { { "action", "play" }, { "WordId", _item.Id.ToString() }, { "PlayId", "2" }, { "PlayUrl", _item.PlayURL2 }, }.ToString()) { ActivationType = ToastActivationType.Background, ActivationOptions = new ToastActivationOptions() { AfterActivationBehavior = ToastAfterActivationBehavior.PendingUpdate } }, new ToastButton("Next", new QueryString() { { "action", "next" }, { "WordId", _item.Id.ToString() }, }.ToString()) { ActivationType = ToastActivationType.Background, ActivationOptions = new ToastActivationOptions() { AfterActivationBehavior = ToastAfterActivationBehavior.PendingUpdate } }, new ToastButton("View", new QueryString() { { "action", "view" }, { "url", viewDicOnlineUrl + _item.Word } }.ToString()), //new ToastButton("Close", "dismiss") //{ // ActivationType = ToastActivationType.Background //}, } }, }; return(content); }
private void CoreApplication_BackgroundActivated(object sender, BackgroundActivatedEventArgs e) { var taskInstance = e.TaskInstance; var deferral = taskInstance.GetDeferral(); var details = taskInstance.TriggerDetails as BackgroundTransferCompletionGroupTriggerDetails; if (details == null) { return; } IReadOnlyList <DownloadOperation> downloads = details.Downloads; var notifier = ToastNotificationManager.CreateToastNotifier(); foreach (var dl in downloads) { try { if (dl.Progress.BytesReceived != dl.Progress.TotalBytesToReceive) { continue; } if (dl.ResultFile == null) { continue; } var file = dl.ResultFile; // ファイル名の最後方にある[]の中身の文字列を取得 // (動画タイトルに[]が含まれる可能性に配慮) var regex = new Regex("(?:(?:sm|so|lv)\\d*)"); var match = regex.Match(file.Name); var id = match.Value; // キャッシュファイルからタイトルを抜き出します // ファイルタイトルの決定は // DividedQualityNicoVideo.VideoFileName プロパティの // 実装に依存します // 想定された形式は以下の形です // タイトル - [sm12345667].mp4 // タイトル - [sm12345667].low.mp4 var index = file.Name.LastIndexOf(" - ["); var title = file.Name.Remove(index); // トーストのレイアウトを作成 ToastContent content = new ToastContent() { Launch = "niconico://" + id, Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title, }, new AdaptiveText() { Text = "キャッシュ完了", HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { Text = "ここをタップして再生を開始", HintStyle = AdaptiveTextStyle.CaptionSubtle } }, /* * AppLogoOverride = new ToastGenericAppLogo() * { * Source = "oneAlarm.png" * } */ } }, /* * Actions = new ToastActionsCustom() * { * Buttons = * { * new ToastButton("check", "check") * { * ImageUri = "check.png" * }, * * new ToastButton("cancel", "cancel") * { * ImageUri = "cancel.png" * } * } * }, */ /* * Audio = new ToastAudio() * { * Src = new Uri("ms-winsoundevent:Notification.Reminder") * } */ }; // トースト表示を実行 ToastNotification notification = new ToastNotification(content.GetXml()); notifier.Show(notification); } catch { } } deferral.Complete(); }
public static void OnMessageReceived(object sender, PushReceivedEventArgs args) { var notificationContent = args.NotificationContent; var igAction = notificationContent.IgAction; var querySeparatorIndex = igAction.IndexOf('?'); var targetType = igAction.Substring(0, querySeparatorIndex); var queryParams = HttpUtility.ParseQueryString(igAction.Substring(querySeparatorIndex)); var threadId = queryParams["id"]; var itemId = queryParams["x"]; var threadTitle = GetThreadTitleFromAppSettings(threadId); if (string.IsNullOrEmpty(threadTitle)) { threadTitle = notificationContent.Message.Substring(0, notificationContent.Message.IndexOf(' ')); } var toastContent = new ToastContent { Header = new ToastHeader(threadId, threadTitle, string.Empty), Visual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = notificationContent.Message } }, HeroImage = string.IsNullOrEmpty(notificationContent.OptionalImage) ? null : new ToastGenericHeroImage { Source = notificationContent.OptionalImage }, AppLogoOverride = string.IsNullOrEmpty(args.NotificationContent.OptionalAvatarUrl) ? null : new ToastGenericAppLogo { Source = args.NotificationContent.OptionalAvatarUrl, HintCrop = ToastGenericAppLogoCrop.Circle, AlternateText = "Profile picture" } } }, Launch = $"action=openThread&threadId={threadId}" }; // Create the toast notification var toast = new ToastNotification(toastContent.GetXml()) { Group = threadId, Tag = itemId, ExpiresOnReboot = false }; if (ApiInformation.IsPropertyPresent("Windows.UI.Notifications.ToastNotification", "RemoteId")) { toast.RemoteId = notificationContent.PushId; } QueueRapidToast(toast); }
public static ToastNotification CreateRegisterReminderToast() { // Generate the toast content var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Be sure to register your new device!" }, new AdaptiveText() { Text = "Click this notification to start the registration process." } } } }, Actions = new ToastActionsCustom() { Inputs = { new ToastSelectionBox(INPUT_SNOOZEMINUTES) { DefaultSelectionBoxItemId = "15", Items = { new ToastSelectionBoxItem("15", "15 minutes"), new ToastSelectionBoxItem("1440", "1 day"), new ToastSelectionBoxItem("4320", "3 days") } } }, Buttons = { // Snoozing will activate our background task new ToastButton("Snooze", ACTION_SNOOZE) { ActivationType = ToastActivationType.Background }, // Dismissing will delete the notification new ToastButtonDismiss() } }, Launch = ACTION_REGISTER, Scenario = ToastScenario.Reminder }; // Create the toast var toast = new ToastNotification(toastContent.GetXml()) { Tag = TAG_REGISTER_REMINDER }; return(toast); }
public static void ShowWhichLunchToast() { ToastContent content = new ToastContent() { Launch = new QueryString() { { "action", "viewwhich" } }.ToString(), Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "which like?" } } } }, Actions = new ToastActionsCustom() { Inputs = { new ToastSelectionBox("lunch") { Items = { new ToastSelectionBoxItem("AAA", "aaa"), new ToastSelectionBoxItem("BBB", "bbb"), new ToastSelectionBoxItem("CCC", "ccc") }, DefaultSelectionBoxItemId = "AAA" } }, Buttons = { new ToastButton("submit", new QueryString() { { "action", "submitOrder"} }.ToString()) { ActivationType = ToastActivationType.Background, ActivationOptions = new ToastActivationOptions() { AfterActivationBehavior = ToastAfterActivationBehavior.PendingUpdate } }, new ToastButtonDismiss("Cancel") } }, //禁用后续音频 Audio = new ToastAudio() { Silent = true } }; ShowToast(content); }
public ToastNotification CreateCallNotification(IEnumerable <Call> currentCalls) { List <Call> calls = currentCalls.Where(x => x.State != CallState.Disconnected && x.State != CallState.Indeterminate).OrderBy(x => x.State).ToList(); ToastBindingGeneric content = new ToastBindingGeneric(); ToastActionsCustom actions = new ToastActionsCustom(); switch (calls.Count) { case 0: return(null); case 1: Call singleCall = calls.First(); foreach (IToastBindingGenericChild child in CreateVisualForCall(singleCall)) { content.Children.Add(child); } foreach (IToastButton button in CreateButtonsForCall(singleCall)) { actions.Buttons.Add(button); } break; default: content.Children.Add(new AdaptiveText() { Text = "Dialer - Active calls" }); for (int i0 = 0; i0 < calls.Count / 2; i0++) { AdaptiveGroup group = new AdaptiveGroup(); for (int i1 = i0 * 2; i1 < i0 * 2 + 2 && i1 < calls.Count; i1++) { AdaptiveSubgroup subgroup = new AdaptiveSubgroup(); foreach (IAdaptiveSubgroupChild child in CreateVisualForCall(calls[i1])) { subgroup.Children.Add(child); } group.Children.Add(subgroup); } content.Children.Add(group); } foreach (IToastButton button in MergeButtons(calls.Select(x => CreateButtonsForCall(x)).SelectMany(x => x))) { actions.Buttons.Add(button); } break; } Call incomingCall = calls.FirstOrDefault(x => x.State == CallState.Incoming); bool hasRingTone = !string.IsNullOrEmpty(incomingCall?.Contact?.RingToneToken); ToastContent toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = content }, Actions = actions, Audio = new ToastAudio() { Silent = calls.Any(x => x.State != CallState.Incoming), Loop = true, Src = hasRingTone ? new Uri(incomingCall.Contact.RingToneToken) : null }, Launch = $"{ACTION}={SHOW_CALL_UI}", Scenario = ToastScenario.IncomingCall }; ToastNotification notification = new ToastNotification(toastContent.GetXml()) { Tag = CALL_NOTIFICATION_UI, ExpiresOnReboot = true, Priority = ToastNotificationPriority.High, Data = new NotificationData() { Values = { { USED_CALLS, calls.Aggregate(new StringBuilder(), (x, y) => x.Append(y.ID).Append(';'), x => x.ToString()) }, { USED_CALLS_STATES, calls.Aggregate(new StringBuilder(), (x, y) => x.Append((uint)y.State).Append(';'), x => x.ToString()) } } } }; return(notification); }
private static void AppUnhandledException(Exception ex) { string formattedException = string.Empty; formattedException += "--------- UNHANDLED EXCEPTION ---------"; if (ex != null) { formattedException += $"\n>>>> HRESULT: {ex.HResult}\n"; if (ex.Message != null) { formattedException += "\n--- MESSAGE ---"; formattedException += ex.Message; } if (ex.StackTrace != null) { formattedException += "\n--- STACKTRACE ---"; formattedException += ex.StackTrace; } if (ex.Source != null) { formattedException += "\n--- SOURCE ---"; formattedException += ex.Source; } if (ex.InnerException != null) { formattedException += "\n--- INNER ---"; formattedException += ex.InnerException; } } else { formattedException += "\nException is null!\n"; } formattedException += "---------------------------------------"; Debug.WriteLine(formattedException); Debugger.Break(); // Please check "Output Window" for exception details (View -> Output Window) (CTRL + ALT + O) SaveSessionTabs(); Logger.Error(ex, formattedException); if (ShowErrorNotification) { var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "ExceptionNotificationHeader".GetLocalized() }, new AdaptiveText() { Text = "ExceptionNotificationBody".GetLocalized() } }, AppLogoOverride = new ToastGenericAppLogo() { Source = "ms-appx:///Assets/error.png" } } }, Actions = new ToastActionsCustom() { Buttons = { new ToastButton("ExceptionNotificationReportButton".GetLocalized(), "report") { ActivationType = ToastActivationType.Foreground } } } }; // Create the toast notification var toastNotif = new ToastNotification(toastContent.GetXml()); // And send the notification ToastNotificationManager.CreateToastNotifier().Show(toastNotif); } }
public WindowsToastService(IToast toast, ToastContent content) { Toast = toast; Content = content; }
private void Show(ToastContent content) { ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml())); }
void Toast() { string title = "Title"; string content = "Content"; string image = "https://picsum.photos/360/202?image=883"; string logo = ""; var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = content }, new AdaptiveImage() { Source = image }, }, AppLogoOverride = new ToastGenericAppLogo() { Source = logo, HintCrop = ToastGenericAppLogoCrop.Circle } }, } }; var tileContent = new TileContent { Visual = new TileVisual { TileMedium = new TileBinding { Content = new TileBindingContentAdaptive { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = content }, new AdaptiveImage() { Source = image }, } } } } }; //send toast var toastNotification = new ToastNotification(toastContent.GetXml()); ToastNotificationManager.CreateToastNotifier().Show(toastNotification); //send tile var tileNotification = new TileNotification(tileContent.GetXml()); TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); //send badge //var badgeContent = new BadgeNumericContent() //{ // Number = 10, //}; //var badgeNotification = new BadgeNotification(badgeContent.GetXml()); //BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeNotification); }
private async void saveButton_ClickAsync(object sender, RoutedEventArgs e) { var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; savePicker.FileTypeChoices.Add("Note", new List <string>() { ".eqn" }); savePicker.SuggestedFileName = "Note"; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { Windows.Storage.CachedFileManager.DeferUpdates(file); await Windows.Storage.FileIO.WriteTextAsync(file, textBox.Text); Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (showNotifications) { // I'M SORRY ABOUT THE AWFUL CODE PRESENTATION HERE // VISUAL STUDIO FILE FORMATION WON'T DO ANYTHING TO IT // PLEASE DO NOT KILL M var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Easy Quick Note" }, new AdaptiveText() { Text = "Saved note." }, new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = "Note name: " + file.Name }, new AdaptiveText() { Text = "Note file path: " + file.Path } } } } } } } }, }; // Create the toast notification var toastNotif = new ToastNotification(toastContent.GetXml()); // And send the notification ToastNotificationManager.CreateToastNotifier().Show(toastNotif); } } }
private void HandleNewAppVersion() { var currentAppVersionString = Package.Current.Id.Version.Major + "." + Package.Current.Id.Version.Minor + "." + Package.Current.Id.Version.Build; // Get stored app version (this will stay the same when app is updated) var storedAppVersionString = SettingsService.Instance.AppStoredVersion; // Save the new app version SettingsService.Instance.AppStoredVersion = currentAppVersionString; // If the stored version is null, set the temp to 0, and the version to the actual version if (!string.IsNullOrEmpty(storedAppVersionString)) { // Convert the current app version var currentAppVersion = new Version(currentAppVersionString); // Convert the stored app version var storedAppVersion = new Version(storedAppVersionString); if (currentAppVersion <= storedAppVersion) { return; } } var clickText = "Tap here to read what's new."; if (DeviceHelper.IsDesktop) { clickText = "Click here to read what's new."; } if (DeviceHelper.IsXbox) { clickText = "Hold down the Xbox button to read what's new."; } // Generate a notification var toastContent = new ToastContent { Visual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = "SoundByte" }, new AdaptiveText { Text = string.IsNullOrEmpty(storedAppVersionString) ? "Thank you for downloading SoundByte!" : $"SoundByte was updated to version {currentAppVersionString}. {clickText}" } } } }, ActivationType = ToastActivationType.Protocol, Launch = "soundbyte://core/changelog" }; // Show the notification var toast = new ToastNotification(toastContent.GetXml()) { ExpirationTime = DateTime.Now.AddMinutes(30) }; ToastNotificationManager.CreateToastNotifier().Show(toast); }
// New method protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args) { var deferral = args.TaskInstance.GetDeferral(); try { RawNotification notification = (RawNotification)args.TaskInstance.TriggerDetails; // Decrypt the content string payload = await PushManager.GetDecryptedContentAsync(notification); // Show a notification // You'll need Microsoft.Toolkit.Uwp.Notifications NuGet package installed for this code ToastContent content = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Push notification received" }, new AdaptiveText() { Text = payload } } } } }; ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml())); } catch (Exception ex) { ToastContent content = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Failed decrypting" }, new AdaptiveText() { Text = ex.ToString() } } } } }; ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(content.GetXml())); } deferral.Complete(); }
/// <summary> /// Show Toast of recieving a Friend Request /// </summary> public void FriendNotification(User user) { string toastTitle = user.Username + " " + App.GetString("/Main/Notifications_SentAfriendRequest"); string userPhoto = "https://cdn.discordapp.com/avatars/" + user.Id + "/" + user.Avatar + ".jpg"; // Construct the visuals of the toast ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = toastTitle, HintMaxLines = 6 } }, AppLogoOverride = new ToastGenericAppLogo() { Source = userPhoto, HintCrop = ToastGenericAppLogoCrop.Circle } } }; // Construct the actions for the toast (inputs and buttons) ToastActionsCustom actions = new ToastActionsCustom() { Buttons = { new ToastButton(App.GetString("/Main/Notifications_Accept"), new QueryString() { { "action", "AddRelationship" }, { "id", user.Id } }.ToString()) { ActivationType = ToastActivationType.Foreground, }, new ToastButton(App.GetString("/Main/Notifications_Refuse"), new QueryString() { { "action", "RemoveRelationship" }, { "id", user.Id } }.ToString()) { ActivationType = ToastActivationType.Foreground, }, } }; // Now we can construct the final toast content ToastContent toastContent = new ToastContent() { Visual = visual, Actions = actions, // Arguments when the user taps body of toast Launch = new QueryString() { { "action", "Navigate" }, { "page", "Friends" } }.ToString() }; // And create the toast notification ToastNotification notification = new ToastNotification(toastContent.GetXml()); // And then send the toast ToastNotificationManager.CreateToastNotifier().Show(notification); }
public async static void SendNotification(string imagepath, string visitoename = "未知", string visitordata = "陌生人") { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString( "<connect string>" , "<Hub name>"); if (visitordata != "陌生人") { var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "嗨!o(* ̄▽ ̄*)ブ,你有新的访客来了~~~" }, new AdaptiveText() { Text = $"好像是{visitordata},{visitoename}" }, new AdaptiveImage() { Source = imagepath } }, AppLogoOverride = new ToastGenericAppLogo() { Source = "https://unsplash.it/64?image=669", HintCrop = ToastGenericAppLogoCrop.Circle } } } }; string toast = toastContent.GetContent(); await hub.SendWindowsNativeNotificationAsync(toast); } else { var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "(⊙﹏⊙)!有陌生人找你!!············" }, new AdaptiveText() { Text = $"好像是{visitordata},{visitoename}" }, new AdaptiveImage() { Source = imagepath } }, AppLogoOverride = new ToastGenericAppLogo() { Source = "https://unsplash.it/64?image=669", HintCrop = ToastGenericAppLogoCrop.Circle } } } }; string toast = toastContent.GetContent(); await hub.SendWindowsNativeNotificationAsync(toast); } }
private void ButtonPopUpAlarmNotification_Click(object sender, RoutedEventArgs e) { /* * string textLine1 = "Sample Toast App"; * string textLine2 = "This is a sample message."; * string contentString = * "<toast duration=\"long\">\n" + * "<visual>\n" + * "<binding template=\"ToastText02\">\n" + * "<text id=\"1\">" + textLine1 + "</text>\n" + * "<text id=\"2\">" + textLine2 + "</text>\n" + * "</binding>\n" + * "</visual>\n" + * "</toast>\n"; * XmlDocument content = new Windows.Data.Xml.Dom.XmlDocument(); * content.LoadXml(contentString); */ var toastContent = new ToastContent() { Visual = new ToastVisual() { BaseUri = new Uri("ms-appx:///Assets/Weather/"), BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = "Today will be sunny with a high of 63 and a low of 42." }, new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = "Mon", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveImage() { HintRemoveMargin = true, Source = "Mostly Cloudy.png" }, new AdaptiveText() { Text = "63°", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveText() { Text = "42°", HintStyle = AdaptiveTextStyle.CaptionSubtle, HintAlign = AdaptiveTextAlign.Center } } }, new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = "Tue", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveImage() { HintRemoveMargin = true, Source = "Cloudy.png" }, new AdaptiveText() { Text = "57°", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveText() { Text = "38°", HintStyle = AdaptiveTextStyle.CaptionSubtle, HintAlign = AdaptiveTextAlign.Center } } }, new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = "Wed", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveImage() { HintRemoveMargin = true, Source = "Sunny.png" }, new AdaptiveText() { Text = "59°", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveText() { Text = "43°", HintStyle = AdaptiveTextStyle.CaptionSubtle, HintAlign = AdaptiveTextAlign.Center } } }, new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = "Thu", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveImage() { HintRemoveMargin = true, Source = "Sunny.png" }, new AdaptiveText() { Text = "62°", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveText() { Text = "42°", HintStyle = AdaptiveTextStyle.CaptionSubtle, HintAlign = AdaptiveTextAlign.Center } } }, new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = "Fri", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveImage() { HintRemoveMargin = true, Source = "Sunny.png" }, new AdaptiveText() { Text = "71°", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveText() { Text = "66°", HintStyle = AdaptiveTextStyle.CaptionSubtle, HintAlign = AdaptiveTextAlign.Center } } } } } } } } }; // Create the toast notification var content = toastContent.GetXml(); // And send the notification //ToastNotificationManager.CreateToastNotifier().Show(toastNotif); ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); var scheduledToast = new ScheduledToastNotification( content, DateTime.Now.AddSeconds(5)); scheduledToast.Tag = "TestTag"; toastNotifier.AddToSchedule(scheduledToast); toastNotifier.ScheduledToastNotificationShowing += ToastNotifier_ScheduledToastNotificationShowing; }