Exemple #1
0
        // Add List Item
        private static AdaptiveElement CreateListItem(AdaptiveListCardItem item, int itemIndex, AdaptiveListCardImageLayout imageLayout, AdaptiveImageSize imageSize = AdaptiveImageSize.Small)
        {
            var columns = new List <AdaptiveColumn>();

            // Add Title, subtitile, text
            var itemContent = new AdaptiveColumn();

            if (!string.IsNullOrEmpty(item.Title))
            {
                itemContent.Items.Add(new AdaptiveTextBlock()
                {
                    Text                = item.Title,
                    Id                  = $"Item-{itemIndex}-Title",
                    Size                = AdaptiveTextSize.Medium,
                    Weight              = AdaptiveTextWeight.Bolder,
                    Spacing             = AdaptiveSpacing.None,
                    HorizontalAlignment = AdaptiveHorizontalAlignment.Left
                });
            }

            if (!string.IsNullOrEmpty(item.Subtitle))
            {
                itemContent.Items.Add(new AdaptiveTextBlock()
                {
                    Text                = item.Subtitle,
                    Id                  = $"Item-{itemIndex}-Subtitle",
                    Size                = AdaptiveTextSize.Default,
                    Spacing             = AdaptiveSpacing.None,
                    IsSubtle            = true,
                    HorizontalAlignment = AdaptiveHorizontalAlignment.Left
                });
            }

            if (!string.IsNullOrEmpty(item.Text))
            {
                itemContent.Items.Add(new AdaptiveTextBlock()
                {
                    Text                = item.Text,
                    Id                  = $"Item-{itemIndex}-Text",
                    Size                = AdaptiveTextSize.Small,
                    Spacing             = AdaptiveSpacing.None,
                    Weight              = AdaptiveTextWeight.Lighter,
                    IsSubtle            = true,
                    HorizontalAlignment = AdaptiveHorizontalAlignment.Left
                });
            }

            // Add List Image
            var itemImage = new AdaptiveColumn()
            {
                Items = new List <AdaptiveElement>(),
                Width = AdaptiveColumnWidth.Auto.ToLower()
            };

            if (item.Image != null && !string.IsNullOrEmpty(item.Image.Url))
            {
                itemImage.Items.Add(AdaptiveElementBuilder.CreateImage(item.Image, imageSize));
            }

            // Set List Item
            switch (imageLayout)
            {
            case AdaptiveListCardImageLayout.Right:
                columns.Add(itemContent);
                columns.Add(itemImage);
                break;

            case AdaptiveListCardImageLayout.Left:
                columns.Add(itemImage);
                columns.Add(itemContent);
                break;

            case AdaptiveListCardImageLayout.None:
            default:
                columns.Add(itemContent);
                break;
            }

            return(new AdaptiveColumnSet()
            {
                Separator = true,
                Columns = columns,
                SelectAction = AdaptiveElementBuilder.CreateAction(item.Tap)
            });
        }
Exemple #2
0
        private static List <AdaptiveElement> CreateListItems(IList <AdaptiveListCardItem> items, AdaptiveListCardImageLayout imageLayout, AdaptiveImageSize imageSize = AdaptiveImageSize.Small)
        {
            var content = new List <AdaptiveElement>();

            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];
                content.Add(CreateListItem(item, i + 1, imageLayout, imageSize));
            }

            return(content);
        }
Exemple #3
0
        // Create List Card
        public static AdaptiveCard CreateListCard(IList <AdaptiveListCardItem> listItem, string title = null, IList <CardAction> buttons = null, AdaptiveListCardImageLayout imageLayout = AdaptiveListCardImageLayout.Right, AdaptiveImageSize imageSize = AdaptiveImageSize.Small, string version = "1.0")
        {
            var adaptiveCard = new AdaptiveCard();
            var body         = new AdaptiveContainer()
            {
                Items = new List <AdaptiveElement>()
            };

            // Add Title
            if (!string.IsNullOrEmpty(title))
            {
                body.Items.AddRange(AdaptiveElementBuilder.CreateTitle(title, AdaptiveTextSize.Large));
            }

            // Add List Item
            body.Items.AddRange(CreateListItems(listItem, imageLayout, imageSize));

            // Set Body and Actions
            adaptiveCard.Body = new List <AdaptiveElement>()
            {
                body
            };
            adaptiveCard.Actions = AdaptiveElementBuilder.CreateActions(buttons);
            adaptiveCard.Version = version;
            return(adaptiveCard);
        }