user1189352
user1189352

Reputation: 3885

Initializing an array of Images

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

Answers (2)

Preston Guillot
Preston Guillot

Reputation: 6724

Your syntax is wrong, you need new Image[] { /* stuff in collection */ }

Upvotes: 4

gleng
gleng

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

Related Questions