我在Hero卡中添加了6个按钮并尝试显示它们.它在团队和模拟器中工作正常但在Skype上不起作用.它只显示3个按钮.
private List<CardAction> GetCardButton(List<string> opts)
{
List<CardAction> cardButtons = new List<CardAction>();
int i = 1;
foreach(string opt in opts)
{
CardAction plButton = new CardAction()
{
Title = opt,
Type = "postBack",
Text = i.ToString(),
Value = i.ToString()
};
cardButtons.Add(plButton);
i++;
}
return cardButtons;
}
//passing list of strings.
List<CardAction> cardButtons = GetCardButton(cardOpts);
HeroCard plCard = new HeroCard()
{
Title = "Try here",
Text = "with:",
Buttons = cardButtons
};
plAttachment = plCard.ToAttachment();
但在Skype中我只看到前3个按钮.有什么方法可以使卡可滚动或减少按钮大小?
解决方法:
如前面的答案所示,每个频道都有可以显示的内容,按钮数量,文本长度等限制.似乎您遇到了这个限制.您可以做的一件事是,如果有三个以上的按钮显示另一张卡并将它们显示在列表或轮播中.
这是一个被黑客攻击的代码示例:
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Bot_Application13.Dialogs
{
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
List<Attachment> cards = new List<Attachment>();
List<CardAction> buttons = new List<CardAction>();
for (int i = 0; i < 10; i++)
{
CardAction ca = new CardAction()
{
Title = i.ToString(),
Type = "postBack",
Text = i.ToString(),
Value = i.ToString()
};
buttons.Add(ca);
}
var reply = context.MakeMessage();
GetCardsAttachments(buttons, cards);
//reply.AttachmentLayout = AttachmentLayoutTypes.List;
//or
reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
reply.Attachments = cards;
await context.PostAsync(reply);
context.Wait(this.MessageReceivedAsync);
}
private Attachment GetHeroCard(List<CardAction> buttons)
{
var heroCard = new HeroCard();
//heroCard.Title = "Title";
heroCard.Buttons = buttons;
return heroCard.ToAttachment();
}
private void GetCardsAttachments(List<CardAction> buttons, List<Attachment> cards)
{
if (buttons.Count <= 3)
{
cards.Add(GetHeroCard(buttons));
}
else
{
var temp = new List<CardAction>();
for (int i = 0; i < buttons.Count; i++)
{
if (i % 3 != 0)
{
temp.Add(buttons.ElementAt(i));
}
else
{
if (i != 0)
{
cards.Add(GetHeroCard(temp));
}
temp = new List<CardAction>();
temp.Add(buttons.ElementAt(i));
}
}
cards.Add(GetHeroCard(temp));
}
}
}
}