private static AdaptiveCards.Rendering.Uwp.AdaptiveCardRenderer CreateRenderer()
        {
            var renderer = SharedAdaptiveCardRenderer.Create();

            string path = Package.Current.InstalledLocation.Path + "\\Previews\\Microsoft.Outlook.ActionableMessage.HostConfig.json";

            renderer.HostConfig = AdaptiveCards.Rendering.Uwp.AdaptiveHostConfig.FromJsonString(File.ReadAllText(path)).HostConfig;

            return(renderer);
        }
        private AdaptiveCards.Rendering.Uwp.AdaptiveCardRenderer CreateRenderer(string hostConfigFileName)
        {
            var renderer = SharedAdaptiveCardRenderer.Create();

            string path = Package.Current.InstalledLocation.Path + "\\Previews\\" + hostConfigFileName;

            renderer.HostConfig = AdaptiveCards.Rendering.Uwp.AdaptiveHostConfig.FromJsonString(File.ReadAllText(path)).HostConfig;

            return(renderer);
        }
Ejemplo n.º 3
0
        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);
            }
        }