呈现卡 - WinUI 3
下面介绍如何使用 WinUI 3 SDK 呈现卡。
创建呈现器实例
创建呈现器库的实例。
using AdaptiveCards.Rendering.WinUI3;
// ...
var renderer = new AdaptiveCardRenderer();
根据 JSON 字符串创建卡片
var card = AdaptiveCard.FromJsonString(jsonString);
从 JSON 对象创建卡
var card = AdaptiveCard.FromJson(jsonObject);
呈现卡片
从源获取卡并呈现它。
RenderedAdaptiveCard renderedAdaptiveCard = renderer.RenderAdaptiveCard(card);
// Check if the render was successful
if (renderedAdaptiveCard.FrameworkElement != null)
{
// Get the framework element
var uiCard = renderedAdaptiveCard.FrameworkElement;
// Add it to your UI
myGrid.Children.Add(uiCard);
}
示例
下面是 WinUI 3 呈现器的示例。
var renderer = new AdaptiveCardRenderer();
var card = AdaptiveCard.FromJsonString(jsonString);
var renderedAdaptiveCard = renderer.RenderAdaptiveCard(card.AdaptiveCard);
if (renderedAdaptiveCard.FrameworkElement != null)
{
myGrid.Children.Add(renderedAdaptiveCard.FrameworkElement);
}
...