从CardImage列表bot框架中选择特定图像



我目前正在构建一个能够构建动态旋转木制卡片的机器人,但是我没有找到许多示例来指定要在哪个卡上使用哪个图像。

public async Task Styles(IDialogContext context, LuisResult result)
        {
            InfoClass IC = new InfoClass();
            int count = IC.BuildArray().Length;
            PolaroidObject[] glasses = IC.BuildArray();
            int x = 0;
            var reply = context.MakeMessage();
            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            //Storing Images into variables
            List<CardImage> images = new List<CardImage>();
            CardImage Ci1 = new CardImage("https://polaroideyewear.com/content/dam/products/brands/pld/2017/04/2003960807lm/high-res/2003960807lm_p00.jpg/_jcr_content/renditions/cq5dam.web.1280.1280.jpeg");
            CardImage Ci2 = new CardImage("https://polaroideyewear.com/content/dam/products/brands/pld/2017/01/20035406lbuc/high-res/20035406lbuc_p00.jpg/_jcr_content/renditions/cq5dam.web.1280.1280.jpeg");
            CardImage Ci3 = new CardImage("https://polaroideyewear.com/en/sunglasses/pld/2017/PLD-4049-S.html");
            CardImage Ci4 = new CardImage("https://polaroideyewear.com/en/sunglasses/pld/2017/PLD-4050-S.html");
            CardImage Ci5 = new CardImage("https://polaroideyewear.com/content/dam/products/brands/pld/2017/04/2003940010ex/high-res/2003940010ex_p00.jpg/_jcr_content/renditions/cq5dam.web.1280.1280.jpeg");
            CardImage Ci6 = new CardImage("https://polaroideyewear.com/content/dam/products/brands/pld/2017/04/2003960807lm/high-res/2003960807lm_p00.jpg/_jcr_content/renditions/cq5dam.web.1280.1280.jpeg");
            CardImage Ci7 = new CardImage("https://polaroideyewear.com/content/dam/products/brands/pld/2017/04/2003960807lm/high-res/2003960807lm_p00.jpg/_jcr_content/renditions/cq5dam.web.1280.1280.jpeg");
            images.Add(Ci1);
            images.Add(Ci2);
            images.Add(Ci3);
            images.Add(Ci4);
            images.Add(Ci5);
            images.Add(Ci6);
            images.Add(Ci7);
            for (int z = 1; z <= count; z++)
            {
                HeroCard hc = new HeroCard()
                {
                    Title = glasses[x].Shape,
                    Images = images
                };
                reply.Attachments.Add(hc.ToAttachment());
                x++;
            }
            await context.PostAsync(reply);
            context.Wait(MessageReceived);
        }

这是我当前这样做的方式,但是它仅加载了列表中的第一个图像。我正在寻找一种使用类似阵列的方式,您可以指定"图像=图像[z]"。

另外,我不确定保存这些图像的最佳方法,我有一个带有图像和get/set类的文件夹。我希望以与我的形状相同的方式打电话给它们,但是它抱怨并要求List<CardImage>而不是字符串。

您需要将一个图像附加到每张卡上,而不是整个列表 - 这样的内容,假设x是索引:

HeroCard hc = new HeroCard()
{
    Title = glasses[x].Shape,
    Images = new List<CardImage> { images[x] }
};

最新更新