从 CardImage List 机器人框架中选择特定图像
Selecting a specific image from CardImage List bot framework
我目前正在构建一个能够构建英雄卡片动态轮播的机器人,但是我还没有找到很多示例来说明要在哪张卡片上使用哪个图像。
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);
}
这是我目前的做法,虽然有效,但它只加载列表中的第一张图片。我正在寻找一种方法来使用类似于数组的方法,您可以在其中指定 "Images = images[z]".
另外,我不确定保存这些图像的最佳方式,我有一个包含图像的文件夹和一个 get/set class。我希望以与处理形状相同的方式调用它们,但是它抱怨并要求 List<CardImage>
而不是字符串。
您需要在每张卡片上附加一张图片,而不是整个列表 - 类似这样,假设 x
是索引:
HeroCard hc = new HeroCard()
{
Title = glasses[x].Shape,
Images = new List<CardImage> { images[x] }
};
我目前正在构建一个能够构建英雄卡片动态轮播的机器人,但是我还没有找到很多示例来说明要在哪张卡片上使用哪个图像。
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);
}
这是我目前的做法,虽然有效,但它只加载列表中的第一张图片。我正在寻找一种方法来使用类似于数组的方法,您可以在其中指定 "Images = images[z]".
另外,我不确定保存这些图像的最佳方式,我有一个包含图像的文件夹和一个 get/set class。我希望以与处理形状相同的方式调用它们,但是它抱怨并要求 List<CardImage>
而不是字符串。
您需要在每张卡片上附加一张图片,而不是整个列表 - 类似这样,假设 x
是索引:
HeroCard hc = new HeroCard()
{
Title = glasses[x].Shape,
Images = new List<CardImage> { images[x] }
};