Reputation: 3885
I have 17 images on my application i created through the xaml in my WPF. I'm trying to insert them into an array for easier coding
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
};
but i'm getting a "Cannot initialize type 'System.Windows.Controls.Image' with a collection initializer because it does not implement 'System.Collections.IEnumerable'" error.
how can i fix this?
Upvotes: 0
Views: 2175
Reputation: 6724
Your syntax is wrong, you need new Image[] { /* stuff in collection */ }
Upvotes: 4
Reputation: 6304
You are not initializing it properly. Use 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
};
Upvotes: 2