public void Test_Toast_Xml_TextBox_Title_Value() { var textBox = new ToastTextBox("myId") { Title = "My title" }; AssertInputPayload("<input id='myId' type='text' title='My title' />", textBox); }
public void Test_Toast_Xml_TextBox_PlaceholderContent_Value() { var textBox = new ToastTextBox("myId") { PlaceholderContent = "My placeholder content" }; AssertInputPayload("<input id='myId' type='text' placeHolderContent='My placeholder content' />", textBox); }
public void Test_Toast_Xml_TextBox_DefaultTextInput_Value() { var textBox = new ToastTextBox("myId") { DefaultInput = "Default text input" }; AssertInputPayload("<input id='myId' type='text' defaultInput='Default text input' />", textBox); }
/// <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); }
public void Test_Toast_Xml_TextBox_EmptyId() { var textBox = new ToastTextBox(""); AssertInputPayload("<input id='' type='text' />", textBox); }
public void Test_Toast_Xml_TextBox_Defaults() { var textBox = new ToastTextBox("myId"); AssertInputPayload("<input id='myId' type='text' />", textBox); }
public static void CreateMentionNotification(string username, string avatar, string guildname, string channelname, string body, string channelid, string guildid, string messageid) { string toastTitle = username + " " + App.GetString("/Main/Notifications_sentMessageOn") + " #" + channelname; if (LocalState.Guilds[guildid].members.ContainsKey(LocalState.CurrentUser.Id)) { body = body.Replace("<@!" + LocalState.CurrentUser.Id + ">", "@" + LocalState.Guilds[guildid].members[LocalState.CurrentUser.Id].Nick); } body = body.Replace("<@" + LocalState.CurrentUser.Id + ">", "@" + LocalState.CurrentUser.Username); ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = toastTitle }, new AdaptiveText() { Text = body }, /*new AdaptiveImage() * { * Source = imageurl * }*/ }, AppLogoOverride = new ToastGenericAppLogo() { Source = avatar, HintCrop = ToastGenericAppLogoCrop.Circle } } }; ToastTextBox replyContent = new ToastTextBox("Reply") { PlaceholderContent = App.GetString("/Main/Notifications_Reply"), }; ToastActionsCustom actions = new ToastActionsCustom() { Inputs = { replyContent }, Buttons = { new ToastButton("Send", "send/" + channelid + "/" + messageid) { ActivationType = ToastActivationType.Background, TextBoxId = replyContent.Id, ImageUri = "Assets/sendicon.png", } } }; ToastContent toastContent = new ToastContent() { Visual = visual, Actions = actions, // Arguments when the user taps body of toast Launch = "quarrel://channels/" + guildid + "/" + channelid, ActivationType = ToastActivationType.Protocol, HintToastId = "Mention" }; ToastNotification notification = new ToastNotification(toastContent.GetXml()); notification.RemoteId = "Mention" + messageid; notification.Group = "Mention"; notification.Tag = messageid; ToastNotificationManager.CreateToastNotifier().Show(notification); }