microsoft / microsoft/AdaptiveCards
[Rendering] UWP not visualize card actions
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2k
- Forks
- 595
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 1
Description
Target Platforms
UWP
SDK Version
3.0.2
Application Name
UWP app
Problem Description
I developed an uwp chat client long time ago where i was using uwp 2.7 but now i want to use 3.0.2. Updating code i found that AdaptiveCardRender doen't render adaptive card actions while it render perfectly actions if you use actionsset
To do some test i wrote a very simple test. here is the codebehind of mainpage:
using AdaptiveCards.ObjectModel.Uwp;
using AdaptiveCards.Rendering.Uwp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Data.Json;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace TestCardRendering
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private AdaptiveHostConfig hostfile = null;
public MainPage()
{
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
if (CardContainer.Children.Count > 0)
{
CardContainer.Children.Clear();
}
AdaptiveCardRenderer renderer = new AdaptiveCardRenderer();
renderer.HostConfig= hostfile;
RenderedAdaptiveCard rac = null;
JsonObject.TryParse(CardJson.Text, out JsonObject jsonObjectCard);
if (jsonObjectCard != null)
{
rac = renderer.RenderAdaptiveCardFromJsonString(CardJson.Text);
var err = rac.Errors;
var war = rac.Warnings;
rac.Action += Rac_Action;
}
if(rac != null && rac.FrameworkElement != null)
{
CardContainer.Children.Add(rac.FrameworkElement);
}
}
private async void Rac_Action(RenderedAdaptiveCard sender, AdaptiveActionEventArgs args)
{
if (args.Action is AdaptiveOpenUrlAction openUrlAction)
{
await Launcher.LaunchUriAsync(openUrlAction.Url);
}
else if (args.Action is AdaptiveShowCardAction showCardAction)
{
// This is only fired if, in HostConfig, you set the ShowCard ActionMode to Popup.
// Otherwise, the renderer will automatically display the card inline without firing this event.
}
else if (args.Action is AdaptiveSubmitAction submitAction)
{
// Get the data and inputs
string data = submitAction.DataJson.Stringify();
string inputs = args.Inputs.AsJson().Stringify();
// Process them as desired
}
}
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
Uri uri = new Uri("ms-appx:///HostConfig/HostConfig.json");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);
string payload = await FileIO.ReadTextAsync(file);
var newHostConfig = AdaptiveHostConfig.FromJsonString(payload).HostConfig;
if (newHostConfig != null)
{
hostfile = newHostConfig;
}
}
}
}
and here the xaml of the same page:
<Page
x:Class="TestCardRendering.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestCardRendering"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<TextBox x:Name="CardJson" HorizontalAlignment="Left" Margin="593,46,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="484" Height="338" RenderTransformOrigin="0.681,0.53"/>
<Button Content="LoadCard" Margin="1096,46,0,0" VerticalAlignment="Top" Width="95" Click="Button_Click"/>
<StackPanel x:Name="CardContainer" BorderThickness="2" BorderBrush="Black" Margin="24,46,932,616"/>
<Button Content="Load Host" Margin="1096,129,0,0" VerticalAlignment="Top" Width="95" Click="Button_Click_1"/>
</Grid>
</Page>
To simulate the issue just copy a payload of a card generate from designer(simplest as possible) and try. Just the body content is rendered
Screenshots
No response
Card JSON
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "test",
"wrap": true
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Action.Submit"
}
],
"id": "card1"
}
Sample Code Language
No response
Sample Code
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the UWP sample, AdaptiveCardRenderer, RenderAdaptiveCardFromJsonString, and the supplied card JSON, then compare the top-level actions with actions inside an ActionSet. Trace the renderer entry point and AdaptiveActionEventArgs handling. Done means top-level Action.Submit controls render and trigger the reported action event as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100