简体   繁体   中英

Dictionary for <string, image>, WP8

I'm trying to create a dictionary with a key/value of string / image for Windows Phone 8.

I understand how dictionaries work, but am unsure of which type I would use for my image.

Essentially, I'm trying to create 26 images, 1 for each letter of the alphabet, so that apple corresponds to an image of an apple.

I'm confused with how to do this on WP8 though, so any guidance in the correct direction would be appreciated

Update: Thank you for the answer. I've still got to be doing something wrong here. For example:

    //Set up the dictionary of AlphaImages objects. 
    if (AlphaImages == null)
    {
        AlphaImages = new Dictionary<string, BitmapImage>();
        AlphaImages.Add("Apple", new BitmapImage(@"Apple.jpg"));
    }

It claims that Im using invalid arguments for the BitmapImage. Following along with this thread, the user takes a different approach with this code:

Dictionary<string, Bitmap> lookup = new Dictionary<string, Bitmap>();
lookup.Add("A", new Bitmap(@"C:\08\letters\1\a1.bmp", true));

and I'm unable to get that to work as well, as the compiler spits out the same error.

What could I be doing wrong?

Try:

AlphaImages.Add("Apple", new BitmapImage(new Uri("Apple.jpg", UriKind.Relative)));

make sure the image is set to have a Build Action of Content.

Air-coded. :)

Also, see here

您正在寻找BitmapImage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM