private void _onAction(object sender, ActionEventArgs e) { if (e.Action is AC.OpenUrlAction) { AC.OpenUrlAction action = (AC.OpenUrlAction)e.Action; Process.Start(action.Url); } else if (e.Action is AC.ShowCardAction) { ShowCardAction action = (AC.ShowCardAction)e.Action; if (HostConfig.Actions.ShowCard.ActionMode == AC.Rendering.Config.ShowCardActionMode.Popup) { ShowCardWindow dialog = new ShowCardWindow(action.Title, action, this.Resources); dialog.Owner = this; dialog.ShowDialog(); } } else if (e.Action is AC.SubmitAction) { AC.SubmitAction action = (AC.SubmitAction)e.Action; System.Windows.MessageBox.Show(this, JsonConvert.SerializeObject(e.Data, Newtonsoft.Json.Formatting.Indented), "SubmitAction"); } else if (e.Action is AC.HttpAction) { AC.HttpAction action = (AC.HttpAction)e.Action; StringBuilder sb = new StringBuilder(); sb.AppendLine($"HEADERS={JsonConvert.SerializeObject(action.Headers)}"); sb.AppendLine($"BODY={action.Body}"); sb.AppendLine($"DATA={e.Data}"); System.Windows.MessageBox.Show(this, sb.ToString(), $"HttpAction {action.Method} {action.Url}"); } }
public ShowCardWindow(string title, ShowCardAction showCardAction, ResourceDictionary resources) { _resources = resources; _card = showCardAction; InitializeComponent(); this.Title = title; }
public FrameworkElement RenderShowCard(ShowCardAction showCard, Func <string, MemoryStream> imageResolver = null, HostConfig hostConfig = null) { RenderContext context = new RenderContext(this.actionCallback, this.missingDataCallback, imageResolver) { Config = hostConfig ?? this.DefaultConfig, Resources = this.Resources, ElementRenderers = this.ElementRenderers }; return(context.Render(showCard.Card)); }
protected static HtmlTag ShowCardActionRender(TypedElement actionElement, RenderContext context) { ShowCardAction action = (ShowCardAction)actionElement; if (context.Config.SupportsInteractivity) { var uiButton = new LinkTag(action.Title, null, $"ac-{action.Type.Replace(".", "").ToLower()}", "ac-action"); return(uiButton); } return(null); }
public static FrameworkElement Render(ShowCardAction action, RenderContext context) { if (context.Config.SupportsInteractivity) { Button uiButton = XamlUtilities.CreateActionButton(action, context); uiButton.Click += (sender, e) => { context.Action(uiButton, new ActionEventArgs() { Action = action, Data = null }); }; return(uiButton); } return(null); }
protected static HtmlTag ShowCardActionRender(ShowCardAction action, RenderContext context) { if (!context.Config.SupportsInteractivity) { return(null); } var buttonElement = new HtmlTag("button") { Text = action.Title } .Attr("type", "button") .Style("overflow", "hidden") .Style("white-space", "nowrap") .Style("text-overflow", "ellipsis") .Style("flex", context.Config.Actions.ActionAlignment == HorizontalAlignment.Stretch ? "0 1 100%" : "0 1 auto") .AddClass("ac-linkButton") .AddClass("ac-showCardAction"); return(buttonElement); }
private void _onAction(object sender, ActionEventArgs e) { if (e.Action is AC.OpenUrlAction) { AC.OpenUrlAction action = (AC.OpenUrlAction)e.Action; Process.Start(action.Url); } else if (e.Action is AC.ShowCardAction) { ShowCardAction action = (AC.ShowCardAction)e.Action; if (HostConfig.Actions.ShowCard.ActionMode == AC.Rendering.Config.ShowCardActionMode.Popup) { ShowCardWindow dialog = new ShowCardWindow(action.Title, action, this.Resources); dialog.Owner = this; dialog.ShowDialog(); } } else if (e.Action is AC.SubmitAction) { AC.SubmitAction action = (AC.SubmitAction)e.Action; System.Windows.MessageBox.Show(this, JsonConvert.SerializeObject(e.Data, Newtonsoft.Json.Formatting.Indented), "SubmitAction"); } }
public HtmlTag RenderShowCard(ShowCardAction showCard) { return(new RenderContext(this.DefaultConfig, this.ElementRenderers).Render(showCard.Card)); }
public virtual void Visit(ShowCardAction action) { Visit(action.Card); }
public Attachment ToCard(Session session) { var card = new AdaptiveCard(); card.Body.Add(new TextBlock() { Text = session.Title, Weight = TextWeight.Bolder, Size = TextSize.Medium, Wrap = true }); card.Body.Add(new TextBlock() { Text = $"{session.Speaker} - {session.Day} at {session.Time}", Size = TextSize.Medium }); //card.Body.Add(new TextBlock() { Text = session.Description, Wrap = true }); ShowCardAction showCardAction = new ShowCardAction(); showCardAction.Title = "Rate this session"; card.Actions.Add(showCardAction); var reviewCard = new AdaptiveCard(); var ratings = new ChoiceSet() { Style = ChoiceInputStyle.Compact, IsMultiSelect = false, Choices = new List <Choice>() { new Choice() { Title = "1", Value = "1" }, new Choice() { Title = "2", Value = "2" }, new Choice() { Title = "3", Value = "3" }, new Choice() { Title = "4", Value = "4" }, new Choice() { Title = "5", Value = "5" }, } }; reviewCard.Body.Add(new TextBlock() { Text = "Let us know what you thought of this session" }); reviewCard.Body.Add(ratings); var data = new { session.Title, Action = "ReviewSession" }; reviewCard.Actions.Add(new SubmitAction() { Title = "Submit feedback", Data = data, DataJson = JsonConvert.SerializeObject(data) }); showCardAction.Card = reviewCard; Attachment attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = card }; return(attachment); }
public static void AddActions(Grid uiContainer, List <ActionBase> actions, RenderContext context) { var maxActions = context.Config.Actions.MaxActions; var actionsToProcess = actions .Take(maxActions).ToList(); if (actionsToProcess.Any() == true) { var uiActionBar = new UniformGrid(); if (context.Config.Actions.ActionsOrientation == ActionsOrientation.Horizontal) { uiActionBar.Columns = actionsToProcess.Count(); } else { uiActionBar.Rows = actionsToProcess.Count(); } uiActionBar.HorizontalAlignment = (System.Windows.HorizontalAlignment)Enum.Parse(typeof(System.Windows.HorizontalAlignment), context.Config.Actions.ActionAlignment.ToString()); uiActionBar.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; uiActionBar.Style = context.GetStyle("Adaptive.Actions"); if (uiContainer.RowDefinitions.Count > 0) { XamlContainer.AddSeperator(context, new Container(), uiContainer); } uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetRow(uiActionBar, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiActionBar); bool isInline = (context.Config.Actions.ShowCard.ActionMode == ShowCardActionMode.Inline); if (isInline && actionsToProcess.Where(a => a is ShowCardAction).Any()) { uiContainer.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); } int iPos = 0; List <FrameworkElement> actionBarCards = new List <FrameworkElement>(); foreach (var action in actionsToProcess) { // add actions var uiAction = (Button)context.Render(action); if (uiAction != null) { if (uiActionBar.Children.Count > 0) { if (context.Config.Actions.ActionsOrientation == ActionsOrientation.Horizontal) { uiAction.Margin = new Thickness(context.Config.Actions.ButtonSpacing, 0, 0, 0); } else { uiAction.Margin = new Thickness(0, context.Config.Actions.ButtonSpacing, 0, 0); } } if (context.Config.Actions.ActionsOrientation == ActionsOrientation.Horizontal) { Grid.SetColumn(uiAction, iPos++); } uiActionBar.Children.Add(uiAction); if (action is ShowCardAction) { ShowCardAction showCardAction = (ShowCardAction)action; if (isInline) { Grid uiShowCardContainer = new Grid(); uiShowCardContainer.Style = context.GetStyle("Adaptive.Actions.ShowCard"); uiShowCardContainer.DataContext = showCardAction; uiShowCardContainer.Margin = new Thickness(0, context.Config.Actions.ShowCard.InlineTopMargin, 0, 0); uiShowCardContainer.Visibility = Visibility.Collapsed; // render the card var uiShowCard = context.Render(showCardAction.Card); ((Grid)uiShowCard).Background = context.GetColorBrush("Transparent"); uiShowCard.DataContext = showCardAction; uiShowCardContainer.Children.Add(uiShowCard); actionBarCards.Add(uiShowCardContainer); Grid.SetRow(uiShowCardContainer, uiContainer.RowDefinitions.Count - 1); uiContainer.Children.Add(uiShowCardContainer); uiAction.Click += (sender, e) => { bool showCard = (uiShowCardContainer.Visibility != Visibility.Visible); foreach (var actionBarCard in actionBarCards) { actionBarCard.Visibility = Visibility.Collapsed; } if (showCard) { uiShowCardContainer.Visibility = Visibility.Visible; } }; } } } } } }
public void OnShowCard(ShowCardAction p0, AdaptiveCard p1) { }