internal static RenderedAdaptiveCard RenderCard(AdaptiveCard card, TypedEventHandler <RenderedAdaptiveCard, AdaptiveActionEventArgs> actionHandler = null) { try { var renderer = SharedAdaptiveCardRenderer.Create(); var inputTextRenderer = renderer.ElementRenderers.Get("Input.Text"); renderer.ElementRenderers.Set("Input.Text", new ActionCenterInputTextRenderer(inputTextRenderer)); // Constructing HostConfig from object model isn't supported yet, have to use JSON var hostConfigResult = AdaptiveHostConfig.FromJsonString(HOST_CONFIG); if (hostConfigResult.HostConfig != null) { renderer.HostConfig = hostConfigResult.HostConfig; } else { throw new Exception("HostConfig failed to parse"); } var result = renderer.RenderAdaptiveCard(card); if (result.FrameworkElement == null) { throw new Exception("Failed to render card"); } if (actionHandler != null) { // Wire up action click handler result.Action += actionHandler; } return(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); PreviewToast.SendRenderingError(ex); return(null); } }
private static RenderedAdaptiveCard Render(string cardJson, bool hasActions, TypedEventHandler <RenderedAdaptiveCard, AdaptiveActionEventArgs> actionHandler = null) { try { var renderer = new AdaptiveCardRenderer(); // Constructing HostConfig from object model isn't supported yet, have to use JSON var hostConfigResult = AdaptiveHostConfig.FromJsonString(HOST_CONFIG); if (hostConfigResult.HostConfig != null) { renderer.HostConfig = hostConfigResult.HostConfig; } else { throw new Exception("HostConfig failed to parse"); } //renderer.SetHostConfig(new AdaptiveHostConfig() //{ // AdaptiveCard = new AdaptiveCardConfig() // { // BackgroundColor = Colors.Transparent, // Padding = new AdaptiveSpacingDefinition() // { // Bottom = 0, // Left = 0, // Right = 0, // Top = 0 // } // }, // Colors = new AdaptiveColorsConfig() // { // Default = new AdaptiveColorConfig() // { // Normal = Colors.White, // Subtle = new Color() { A = 153, R = 255, G = 255, B = 255 } // } // } //}); var cardResult = AdaptiveCard.FromJsonString(cardJson); if (cardResult.AdaptiveCard == null) { throw new Exception("Failed to parse card"); } var result = renderer.RenderAdaptiveCard(cardResult.AdaptiveCard); if (result.FrameworkElement == null) { throw new Exception("Failed to render card"); } if (actionHandler != null) { // Wire up action click handler result.Action += actionHandler; } return(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); PreviewToast.SendRenderingError(ex); return(null); } }