我目前正在構建一個能夠構建英雄卡動態輪播的機器人,但是我還沒有找到很多示例來指定在哪張卡上使用哪個圖像。從CardImage中選擇一個特定的圖像List 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);
}
這是我目前的做法,這個工作,但它只加載列表中的第一個圖像。我正在尋找一種方法來使用像你這樣的數組,你可以指定「Images = images [z]」。
另外,在附註中,我不確定保存這些圖像的最佳方式,我有一個帶有圖像和get/set類的文件夾。我希望以與我做形狀相同的方式稱呼他們,但它抱怨並要求列表而不是字符串。
如果有人有更好的建議,我會很感激。
什麼是'count'的價值?當你說它只加載第一張圖片時,這可能是原因。你的'for'循環是用'z'聲明的,但你永遠不會使用'z' ...你用'x'? – Kyle