Partekatu honen bidez:


Representación de una tarjeta: .NET WPF

A continuación se muestra cómo representar una tarjeta mediante el SDK de .NET WPF.

Nota

Media con direcciones URL HTTPS no funcionará en WPF

Debido a un error en el control MediaElement de WPF, no es posible representar elementos multimedia que se suministran mediante HTTPS. Mientras se resuelve este problema, use direcciones URL HTTP en el elemento Media.

Creación de una instancia de representador

Cree una instancia de la biblioteca de representador.

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;

Representación de una tarjeta en 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
}