我有这个错误:
无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List”
对于以下代码:
当我尝试添加到列表中时:
if (information != null) // not empty
{
foreach (CharacterInformation info in information)
{
chButtons.Add(new GuiSelectCharacterButton(
selectGui,
new Rectangle(100, 100, 450, 100)
));
chButtons[chButtons.Count - 1].ImageTexture = GUISprites.Instance().GetTexture(UITexture.RainbowDash);
chButtons[chButtons.Count - 1].Texture = GUISprites.Instance().GetTexture(UITexture.CommonButtonNotPressed);
chButtons[chButtons.Count - 1].PressedTexture = GUISprites.Instance().GetTexture(UITexture.CommonButtonPressed);
chButtons[chButtons.Count - 1].ImageTextureWidth = 90;
chButtons[chButtons.Count - 1].ImageTextureHeight = 90;
chButtons[chButtons.Count - 1].ButtonPressed += LoginCharacterHandler;
chButtons[chButtons.Count - 1].Font = GameFonts.Instance().GetSpriteFont(FontType.UI);
chButtons[chButtons.Count - 1].Information = information[chButtons.Count - 1];
}
}
// error at this line
buttoncontainer.ButtonList = chButtons;
类声明:
public class GuiSelectCharacterButton : GUIImageButton, IGameUserInterfaceImageButton
{
public GuiSelectCharacterButton(GUI parent, Rectangle area)
: base(parent, area)
{
}
}
界面:
public interface IGameUserInterfaceImageButton : IGameUserInterfaceComponent
{
bool InsideContainer { get; set; }
Rectangle InsideContainerArea { get; set; }
}
IGameUserInterfaceImageButton 列表:
private List<IGameUserInterfaceImageButton> buttonList;
public List<IGameUserInterfaceImageButton> ButtonList
{
get
{
return buttonList;
}
set
{
buttonList = value;
scrollbarThumbTotalHeight = marginButtons;
scrollbarThumbY = 0;
int yhelper = 0;
foreach (IGameUserInterfaceImageButton button in buttonList)
{
yhelper += marginButtons;
button.InsideContainer = true;
button.InsideContainerArea = new Rectangle(
marginXbutton,
yhelper,
button.Area.Width,
button.Area.Height
);
yhelper += marginButtons + button.Area.Height;
scrollbarThumbTotalHeight += button.Area.Height + marginButtons * 2;
}
scrollbarThumbDrawHeight = 0;
if (scrollbarThumbTotalHeight > Area.Height)
{
scrollbarThumbDrawHeight = (int)Math.Pow(AreaScrollbar.Height, 2) / scrollbarThumbTotalHeight;
}
}
}
我不知道我的错误在哪里。基类 (GUIImageButton) 实现了所述接口的所有内容。我在程序的其他部分这样做了,但由于任何奇怪的原因,它在这里不起作用。