Example #1
0
        protected override void LoadPayload(string payload)
        {
            try
            {
                HostConfig = AdaptiveHostConfig.CreateHostConfigFromJson(payload);

                HostConfigChanged?.Invoke(this, HostConfig);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                SetSingleError(new ErrorViewModel()
                {
                    Message = "Invalid Host Config payload",
                    Type    = ErrorViewModelType.ErrorButRenderAllowed
                });
            }
        }
Example #2
0
        public MainPage()
        {
            this.InitializeComponent();

            // Construct a temporary object model tree until the parser is available
            AdaptiveCard      card       = new AdaptiveCard();
            AdaptiveContainer container1 = new AdaptiveContainer();

            AdaptiveTextBlock textBlock1 = new AdaptiveTextBlock();

            textBlock1.Text   = "Hello";
            textBlock1.Weight = TextWeight.Normal;
            textBlock1.Color  = TextColor.Warning;
            textBlock1.Size   = TextSize.Large;
            container1.Items.Add(textBlock1);
            AdaptiveTextBlock textBlock2 = new AdaptiveTextBlock();

            textBlock2.Text   = "World";
            textBlock2.Weight = TextWeight.Normal;
            textBlock2.Color  = TextColor.Accent;
            container1.Items.Add(textBlock2);

            card.Body.Add(container1);

            AdaptiveContainer container2 = new AdaptiveContainer();

            AdaptiveTextBlock textBlock3 = new AdaptiveTextBlock();

            textBlock3.Text   = "In new container";
            textBlock3.Weight = TextWeight.Normal;
            textBlock3.Color  = TextColor.Default;
            container2.Items.Add(textBlock3);

            card.Body.Add(container2);

            AdaptiveImage image = new AdaptiveImage();

            image.Url = new Uri("https://unsplash.it/360/202?image=883");
            card.Body.Add(image);

            m_renderer = new AdaptiveCards.XamlCardRenderer.XamlCardRenderer();

            AdaptiveHostConfig hostConfig = AdaptiveHostConfig.CreateHostConfigFromJson(hostConfigString);

            m_renderer.SetHostConfig(hostConfig);

            m_renderer.Action += async(sender, e) =>
            {
                if (m_actionDialog != null)
                {
                    m_actionDialog.Hide();
                }

                m_actionDialog = new ContentDialog();

                if (e.Action.ActionType == ActionType.ShowCard)
                {
                    AdaptiveShowCardAction showCardAction = (AdaptiveShowCardAction)e.Action;
                    m_actionDialog.Content = await m_renderer.RenderCardAsXamlAsync(showCardAction.Card);
                }
                else
                {
                    m_actionDialog.Content = "We got an action!\n" + e.Action.ActionType + "\n" + e.Inputs;
                }

                m_actionDialog.PrimaryButtonText = "Close";

                await m_actionDialog.ShowAsync();
            };

            PopulateXamlContent(card);
        }