我的应用程序中有17张图像是通过我的WPF中的xaml创建的。我正在尝试将它们插入数组中以便于编码
private static Image[] AllImageArr;
AllImageArr = new Image
{
BluePick1_Image, BluePick2_Image, BluePick3_Image, BluePick4_Image, BluePick5_Image,
RedPick1_Image, RedPick2_Image, RedPick3_Image, RedPick4_Image, RedPick5_Image,
BlueBan1_Image, BlueBan2_Image, BlueBan3_Image,
RedBan1_Image, RedBan2_Image, RedBan3_Image
};
但我得到一个“无法用集合初始化程序初始化类型'System.Windows.Controls.Image',因为它没有实现'System.Collections.IEnumerable'”错误。
我该如何解决这个问题?
答案 0 :(得分:4)
您的语法错误,需要new Image[] { /* stuff in collection */ }
答案 1 :(得分:2)
您没有正确初始化它。使用Image[]
:
AllImageArr = new Image[]
{
BluePick1_Image, BluePick2_Image, BluePick3_Image, BluePick4_Image, BluePick5_Image,
RedPick1_Image, RedPick2_Image, RedPick3_Image, RedPick4_Image, RedPick5_Image,
BlueBan1_Image, BlueBan2_Image, BlueBan3_Image,
RedBan1_Image, RedBan2_Image, RedBan3_Image
};