Exemplo n.º 1
0
        private void RenderCards(JToken attachments)
        {
            string layout = Convert.ToString(attachments.Parent.Parent["attachmentLayout"]);

            if (layout != "carousel")
            {
                return;
            }

            List <CardContext> imageCards     = new List <CardContext>();
            CardPickerContext  cardContext    = new CardPickerContext();
            PickerItem         cardPickerItem = new PickerItem {
                Context = cardContext
            };

            foreach (JToken attachment in attachments)
            {
                List <CardActionContext> actions = new List <CardActionContext>();
                foreach (var action in attachment["buttons"])
                {
                    var localAction = action;
                    actions.Add(new CardActionContext()
                    {
                        Text    = Convert.ToString(localAction["title"]),
                        Command = new Command(() =>
                        {
                            this.chat.Items.Remove(cardPickerItem);
                            string actionText = Convert.ToString(localAction["value"]);
                            this.chat.Items.Add(new TextMessage()
                            {
                                Text = actionText, Author = this.chat.Author
                            });
                        })
                    });
                }

                ImageCardContext imageContext = new ImageCardContext();
                if (attachment["images"] != null && attachment["images"].Count() > 0)
                {
                    imageContext.Image = (Convert.ToString(attachment["images"][0]["url"]));
                }

                imageContext.Title    = Convert.ToString(attachment["title"]);
                imageContext.Subtitle = Convert.ToString(attachment["subtitle"]);
                imageContext.Actions  = actions;

                imageCards.Add(imageContext);
            }

            cardContext.Cards = imageCards;

            this.chat.Items.Add(cardPickerItem);
        }
Exemplo n.º 2
0
        public CustomCard()
        {
            InitializeComponent();

            PickerItem pickerItem = new PickerItem();
            var        context    = new CardPickerContext {
                Cards = this.GetCards(pickerItem)
            };

            pickerItem.Context = context;
            chat.Items.Add(new TextMessage {
                Text = "Select a contact"
            });
            chat.Items.Add(pickerItem);
        }
Exemplo n.º 3
0
        public ChooseCard()
        {
            InitializeComponent();

            // >> chat-chatpicker-cardpicker-pickeritem
            PickerItem pickerItem = new PickerItem();
            var        context    = new CardPickerContext {
                Cards = this.GetCards(pickerItem)
            };

            pickerItem.Context = context;
            chat.Items.Add(new TextMessage {
                Text = "Select a destination"
            });
            chat.Items.Add(pickerItem);
            // << chat-chatpicker-cardpicker-pickeritem
        }
Exemplo n.º 4
0
        private ChatItem CreateCarouselPickerItem(Activity activity)
        {
            CardPickerContext  cardContext    = new CardPickerContext();
            List <CardContext> imageCards     = new List <CardContext>();
            PickerItem         cardPickerItem = new PickerItem();

            foreach (Attachment attachment in activity.Attachments)
            {
                if (attachment.ContentType != "application/vnd.microsoft.card.hero")
                {
                    continue;
                }

                ImageCardContext imageContext = this.CreateImageContext(cardPickerItem, attachment);
                imageCards.Add(imageContext);
            }

            cardContext.Cards      = imageCards;
            cardPickerItem.Context = cardContext;

            return(cardPickerItem);
        }