public IAdaptiveCardElement FromJson(JsonObject inputJson, AdaptiveElementParserRegistration elementParsers, AdaptiveActionParserRegistration actionParsers, IList <AdaptiveWarning> warnings) { JsonObject jsonTextBlock = inputJson.GetNamedObject("internalTextBlock"); var textBlockParser = elementParsers.Get("TextBlock"); IAdaptiveCardElement textBlockElement = textBlockParser.FromJson(jsonTextBlock, elementParsers, actionParsers, warnings); return(new TestCustomElement(textBlockElement) as IAdaptiveCardElement); }
public UIElement Render(IAdaptiveCardElement element, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs) { UIElement renderedOriginalInput = m_originalRenderer.Render(element, context, renderArgs); if (renderedOriginalInput != null) { try { var input = element as AdaptiveTextInput; if (input != null) { JsonObject inlineAction = input.AdditionalProperties.GetNamedObject("inlineAction"); if (inlineAction != null) { string icon = inlineAction.GetNamedString("iconUrl"); if (icon != null) { var renderedIcon = new Image() { Source = new BitmapImage(new Uri(icon)), Width = 30, Height = 30, Stretch = Windows.UI.Xaml.Media.Stretch.Uniform, Margin = new Thickness(12, 0, 0, 0) }; Grid.SetColumn(renderedIcon, 1); return(new Grid() { ColumnDefinitions = { new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition() { Width = GridLength.Auto } }, Children = { renderedOriginalInput, renderedIcon } }); } } } } catch { } } return(renderedOriginalInput); }
public void ValidateBaseElementProperties( IAdaptiveCardElement element, string id, bool isVisible, bool separator, Spacing spacing, HeightType height) { Assert.AreEqual(id, element.Id); Assert.AreEqual(isVisible, element.IsVisible); Assert.AreEqual(separator, element.Separator); Assert.AreEqual(spacing, element.Spacing); Assert.AreEqual(height, element.Height); }
public UIElement Render(IAdaptiveCardElement element, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs) { try { var json = element.ToJson(); var obj = json.GetNamedObject("-ms-action"); return(new TextBlock() { Text = "-ms-action" }); } catch { } return(_originalRenderer.Render(element, context, renderArgs)); }
public void ElementParserRegistraton_CustomElementTest() { AdaptiveActionParserRegistration actionParserRegistration = new AdaptiveActionParserRegistration(); AdaptiveElementParserRegistration elementParserRegistration = new AdaptiveElementParserRegistration(); List <AdaptiveWarning> warnings = new List <AdaptiveWarning>(); elementParserRegistration.Set("TestCustomElement", new TestElementParser()); IAdaptiveElementParser testElementParserRetrieved = elementParserRegistration.Get("TestCustomElement"); Assert.IsNotNull(testElementParserRetrieved); Assert.IsNotNull(testElementParserRetrieved as TestElementParser); String testCard = "{" + " \"type\":\"AdaptiveCard\"," + " \"version\":\"1.0\"," + " \"body\":" + " [" + " {" + " \"type\":\"TestCustomElement\"," + " \"internalTextBlock\":" + " {" + " \"type\":\"TextBlock\"," + " \"text\":\"Here is some text\"" + " }" + " }" + " ]" + "}"; AdaptiveCard card = AdaptiveCard.FromJsonString(testCard, elementParserRegistration, actionParserRegistration).AdaptiveCard; Assert.IsNotNull(card); Assert.AreEqual(1, card.Body.Count); IAdaptiveCardElement cardElement = card.Body[0]; Assert.IsNotNull(cardElement); Assert.AreEqual(ElementType.Custom, cardElement.ElementType); Assert.AreEqual("TestCustomElement", cardElement.ElementTypeString); TestCustomElement customElement = card.Body[0] as TestCustomElement; Assert.IsNotNull(customElement); Assert.AreEqual(ElementType.TextBlock, customElement.InternalTextBlock.ElementType); }
public UIElement Render(IAdaptiveCardElement element, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs) { var card = new AdaptiveCard(); foreach (var a in (element as AdaptiveActionSet).Actions) { card.Actions.Add(a); } var originalPadding = m_cardRenderer.HostConfig.Spacing.Padding; m_cardRenderer.HostConfig.Spacing.Padding = 0; var result = m_cardRenderer.RenderAdaptiveCard(card).FrameworkElement; m_cardRenderer.HostConfig.Spacing.Padding = originalPadding; return(result); }
public TestCustomElement(IAdaptiveCardElement internalTextBlock) { InternalTextBlock = internalTextBlock; }