public static FrameworkElement RenderAdaptiveCardWrapper(AdaptiveCard card, AdaptiveRenderContext context) { var outerGrid = new Grid(); outerGrid.Style = context.GetStyle("Adaptive.Card"); outerGrid.Background = context.GetColorBrush(context.Config.ContainerStyles.Default.BackgroundColor); outerGrid.SetBackgroundSource(card.BackgroundImage, context); var grid = new Grid(); grid.Style = context.GetStyle("Adaptive.InnerCard"); grid.Margin = new Thickness(context.Config.Spacing.Padding); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); AdaptiveContainerRenderer.AddContainerElements(grid, card.Body, context); AdaptiveActionSetRenderer.AddActions(grid, card.Actions, context); outerGrid.Children.Add(grid); return(outerGrid); }
public static FrameworkElement RenderAdaptiveCardWrapper(AdaptiveCard card, AdaptiveRenderContext context) { var outerGrid = new Grid(); outerGrid.Style = context.GetStyle("Adaptive.Card"); outerGrid.Background = context.GetColorBrush(context.Config.ContainerStyles.Default.BackgroundColor); outerGrid.SetBackgroundSource(card.BackgroundImage, context); if (context.CardRoot == null) { context.CardRoot = outerGrid; } // Reset the parent style context.RenderArgs.ParentStyle = AdaptiveContainerStyle.Default; var grid = new Grid(); grid.Style = context.GetStyle("Adaptive.InnerCard"); grid.Margin = new Thickness(context.Config.Spacing.Padding); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); switch (card.VerticalContentAlignment) { case AdaptiveVerticalContentAlignment.Center: grid.VerticalAlignment = VerticalAlignment.Center; break; case AdaptiveVerticalContentAlignment.Bottom: grid.VerticalAlignment = VerticalAlignment.Bottom; break; case AdaptiveVerticalContentAlignment.Top: default: break; } AdaptiveContainerRenderer.AddContainerElements(grid, card.Body, context); AdaptiveActionSetRenderer.AddActions(grid, card.Actions, context); // Only handle Action show cards for the main card if (context.CardDepth == 1) { // Define a new row to contain all the show cards if (context.ActionShowCards.Count > 0) { grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); } foreach (var showCardTuple in context.ActionShowCards) { var currentShowCard = showCardTuple.Value; var uiButton = showCardTuple.Key; Grid.SetRow(currentShowCard, grid.RowDefinitions.Count - 1); grid.Children.Add(currentShowCard); // Assign on click function to all button elements uiButton.Click += (sender, e) => { bool isCardCollapsed = (currentShowCard.Visibility != Visibility.Visible); // Collapse all the show cards foreach (var t in context.ActionShowCards) { var showCard = t.Value; showCard.Visibility = Visibility.Collapsed; } // If current card is previously collapsed, show it if (isCardCollapsed) { currentShowCard.Visibility = Visibility.Visible; } }; } } outerGrid.Children.Add(grid); if (card.SelectAction != null) { var outerGridWithSelectAction = context.RenderSelectAction(card.SelectAction, outerGrid); return(outerGridWithSelectAction); } return(outerGrid); }