【发布时间】:2021-07-29 15:24:29
【问题描述】:
我正在尝试在我们的一个 WPF 应用程序中呈现自适应卡片。由于我对 WPF 很陌生,我想先实现并展示基本的自适应卡,然后再转向实际需求。 我已经实现了MS Link for rendering adaptive card using .Net WPF SDK 中显示的示例。我尝试了相同的解决方案并进行了一些必要的更改,如下所示。
MainWindow.XAML:
<Window x:Class="MyFirstWPFDotNetApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid x:Name="RenderAdaptiveCard" Margin="10" Background="WhiteSmoke">
<Grid.Effect>
<DropShadowEffect BlurRadius="15" ShadowDepth="2" RenderingBias="Quality" Direction="-90"/>
</Grid.Effect>
</Grid>
</Grid>
</Window>
代码背后的代码:
using AdaptiveCards;
using AdaptiveCards.Rendering.Wpf;
using System.Collections.Generic;
using System.Windows;
namespace MyFirstWPFApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
LoadAdaptiveCard();
}
private void LoadAdaptiveCard()
{
// Create a card renderer
AdaptiveCardRenderer renderer = new AdaptiveCardRenderer();
// If using the Xceed package, enable the enhanced input
renderer.UseXceedElementRenderers();
// For fun, check the schema version this renderer supports
AdaptiveSchemaVersion schemaVersion = renderer.SupportedSchemaVersion;
// Build a simple card
// In the real world this would probably be provided as JSON
AdaptiveCard card = new AdaptiveCard("1.0")
{
Body = { new AdaptiveTextBlock() { Text = "Hello World", Id="textWord" } }
};
try
{
// Render the card
RenderedAdaptiveCard renderedCard = renderer.RenderCard(card);
// Get the FrameworkElement
// Add this to your app's UI somewhere
RenderAdaptiveCard.Children.Clear();
RenderAdaptiveCard.Children.Add(renderedCard.FrameworkElement); // Added this line to render it into grid
// (Optional) Check for any renderer warnings
// This includes things like an unknown element type found in the card
// Or the card exceeded the maximum number of supported actions, etc
IList<AdaptiveWarning> warnings = renderedCard.Warnings;
}
catch (AdaptiveException ex)
{
// Failed rendering
}
}
}
}
我在 .Net framework 4.7.1 和 .Net core 3.1 中都尝试了相同的代码,但在这两个应用程序中我都收到错误消息
值不能为空。参数名称:键
在线renderer.RenderCard(card);。我不明白这个例子是一半还是我需要添加一些其他引用或参数?尝试了一些研究,但没有找到关于这个主题的任何帮助。
【问题讨论】:
标签: c# .net wpf asp.net-core-3.1 adaptive-cards