public XmlDocument Build(Note note) { var visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = note.Title, }, new AdaptiveText() { Text = note.Text, }, }, } }; var selectionBox = new ToastSelectionBox("snoozeTime") { DefaultSelectionBoxItemId = "15", Title = "Snooze until:", }; selectionBox.Items.Add(new ToastSelectionBoxItem("5", "5 minutes")); selectionBox.Items.Add(new ToastSelectionBoxItem("15", "15 minutes")); selectionBox.Items.Add(new ToastSelectionBoxItem("60", "1 hour")); selectionBox.Items.Add(new ToastSelectionBoxItem("240", "4 hours")); selectionBox.Items.Add(new ToastSelectionBoxItem("1440", "1 day")); var actions = new ToastActionsCustom() { Inputs = { selectionBox, }, Buttons = { new ToastButtonSnooze { SelectionBoxId = selectionBox.Id, }, new ToastButtonDismiss(), } }; var toastContent = new ToastContent() { Visual = visual, Actions = actions, Scenario = ToastScenario.Reminder, }; var xml = toastContent.GetXml(); return(xml); }
public void Test_Toast_Xml_SelectionBox_Title_Value() { var selectionBox = new ToastSelectionBox("myId") { Title = "My title" }; AssertInputPayload("<input id='myId' type='selection' title='My title' />", selectionBox); }
public void Test_Toast_Xml_SelectionBox_DefaultSelectionBoxItemId_Value() { var selectionBox = new ToastSelectionBox("myId") { DefaultSelectionBoxItemId = "2" }; AssertInputPayload("<input id='myId' type='selection' defaultInput='2' />", selectionBox); }
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); }
private void OnSendNotificationWithExtension(object sender, RoutedEventArgs e) { ToastVisual visual = new ToastVisual { AppLogoOverride = new ToastAppLogo { Crop = ToastImageCrop.None, Source = new ToastImageSource("ms-appx:///Assets/MicrosoftLogo.png") }, TitleText = new ToastText { Text = "DotNet Spain Conference" }, BodyTextLine1 = new ToastText { Text = "How much do you like my session ?" } }; ToastSelectionBox selection = new ToastSelectionBox("rating"); selection.Items.Add(new ToastSelectionBoxItem("1", "1 (Not very much)")); selection.Items.Add(new ToastSelectionBoxItem("2", "2")); selection.Items.Add(new ToastSelectionBoxItem("3", "3")); selection.Items.Add(new ToastSelectionBoxItem("4", "4")); selection.Items.Add(new ToastSelectionBoxItem("5", "5 (A lot!)")); ToastButton button = new ToastButton("Vote", "vote"); button.ActivationType = ToastActivationType.Background; ToastContent toast = new ToastContent { Visual = visual, ActivationType = ToastActivationType.Background, Actions = new ToastActionsCustom { Inputs = { selection }, Buttons = { button } } }; XmlDocument doc = toast.GetXml(); ToastNotification notification = new ToastNotification(doc); ToastNotificationManager.CreateToastNotifier().Show(notification); }
public void Test_Toast_Xml_SelectionBox_EmptyId() { var selectionBox = new ToastSelectionBox(""); AssertInputPayload("<input id='' type='selection' />", selectionBox); }
public void Test_Toast_Xml_SelectionBox_Defaults() { var selectionBox = new ToastSelectionBox("myId"); AssertInputPayload("<input id='myId' type='selection' />", selectionBox); }
protected override Task TransformAsync(AdaptiveBlock block, AdaptiveBlockTransformResult <ToastContent> result) { ToastContent content = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() } }; var finalBlocks = block.GetFinalBlocks(); var firstBlock = finalBlocks.First(); var firstBlockContent = firstBlock.View?.Content; if (firstBlockContent != null) { foreach (var t in firstBlockContent.Text.Take(3)) { content.Visual.BindingGeneric.Children.Add(new AdaptiveText() { Text = t.Text }); } var profileOrIconImageRequest = new AdaptiveBlockContentConsumer.ImageMatchRequest() { RequiredHint = { AdaptiveBlockImageCategoryHints.Profile, AdaptiveBlockImageCategoryHints.Icon } }; var heroImageRequest = new AdaptiveBlockContentConsumer.ImageMatchRequest() { HintsToAvoid = { AdaptiveBlockImageCategoryHints.Icon } }; AdaptiveBlockContentConsumer.MatchImages(firstBlockContent, profileOrIconImageRequest, heroImageRequest); if (heroImageRequest.ImageResult != null) { content.Visual.BindingGeneric.HeroImage = new ToastGenericHeroImage() { Source = heroImageRequest.ImageResult.Url }; } if (profileOrIconImageRequest.ImageResult != null) { content.Visual.BindingGeneric.AppLogoOverride = new ToastGenericAppLogo() { Source = profileOrIconImageRequest.ImageResult.Url, HintCrop = profileOrIconImageRequest.ImageResult.Hints.Category.Contains(AdaptiveBlockImageCategoryHints.Profile) ? ToastGenericAppLogoCrop.Circle : ToastGenericAppLogoCrop.Default }; } if (finalBlocks.Count() > 1) { foreach (var extraBlock in finalBlocks.Skip(1)) { if (extraBlock.View?.Content != null) { content.Visual.BindingGeneric.Children.Add(CreateGroup(extraBlock.View.Content)); } } } if (block.View.Attributes?.AttributionText?.Text != null) { content.Visual.BindingGeneric.Attribution = new ToastGenericAttributionText() { Text = block.View.Attributes?.AttributionText?.Text }; } if (firstBlockContent.Actions.Any()) { content.Actions = new ToastActionsCustom(); var toastActions = content.Actions as ToastActionsCustom; foreach (var a in firstBlockContent.Actions) { // Quick reply style if (a is AdaptiveAction singleFinalAction && a.Inputs.Count == 1 && a.Inputs.First() is AdaptiveTextInputBlock singleTextInput) { toastActions.Inputs.Add(new ToastTextBox(singleTextInput.Id) { PlaceholderContent = singleTextInput.Placeholder }); var button = CreateButton(singleFinalAction); button.TextBoxId = singleTextInput.Id; toastActions.Buttons.Add(button); } else { foreach (var input in a.Inputs) { if (input is AdaptiveTextInputBlock textInput) { toastActions.Inputs.Add(new ToastTextBox(textInput.Id) { PlaceholderContent = textInput.Placeholder, Title = textInput.Title }); } else if (input is AdaptiveChoiceSetInputBlock choiceInput) { var selectionBox = new ToastSelectionBox(choiceInput.Id) { Title = choiceInput.Title }; foreach (var val in choiceInput.Choices) { selectionBox.Items.Add(new ToastSelectionBoxItem(val.Value, val.Title)); } toastActions.Inputs.Add(selectionBox); } } List <AdaptiveAction> finalActions; if (a is AdaptiveSharedInputActions sharedActions) { finalActions = sharedActions.Actions; } else if (a is AdaptiveAction finalAction) { finalActions = new List <AdaptiveAction>() { finalAction }; } else { finalActions = new List <AdaptiveAction>(); } foreach (var finalAction in finalActions) { toastActions.Buttons.Add(CreateButton(finalAction)); } } } }