呈现卡片 - .NET WPF
下面介绍如何使用 .NET WPF SDK 来呈现卡片。
注意
Media
使用 HTTPS URL 在 WPF 中不起作用
由于 WPF 的 MediaElement 控件中存在 Bug,我们不能呈现通过 HTTPS 提供的媒体。 在此问题得到解决前,应该在 Media
元素中使用 HTTP URL。
实例化呈现器
创建呈现器库的实例。
using AdaptiveCards;
using AdaptiveCards.Rendering;
using AdaptiveCards.Rendering.Wpf;
// ...
// 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;
将卡片呈现为 XAML
// 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" } }
};
try
{
// Render the card
RenderedAdaptiveCard renderedCard = renderer.RenderCard(card);
// Get the FrameworkElement
// Add this to your app's UI somewhere
FrameworkElement fe = renderedCard.FrameworkElement;
// (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
}