2

I want to load some images into a ListBox. These images are inside XAP.

Someone tell me that I can use ResourceManager, but I don't know how to get a list for all images inside a folder like "/Assets/Images/".

These images are added as Content.

Any advice?

VansFannel
  • 45,055
  • 107
  • 359
  • 626

2 Answers2

2

If images are set to be content, then you can access them by their relative URLs. So, for example, in code-behind you could do something like this:

BitmapImage image = new BitmapImage(new Uri("/Assets/Images/image1.png",UriKind.Relative));
ImageControl.Source = image;

Same way you can reference them in XAML. However, on Windows Phone you cannot directly list them. You could have an XML file, for example, that keeps the names of existing images, and then read it and read images recursively.

Den
  • 16,686
  • 4
  • 47
  • 87
  • I used an XML file in to keep track of the sample images in the XAP for my barcode scanning app. You can download and reuse the code in other apps if you want. http://silverlightzxing.codeplex.com – Greg Bray May 13 '11 at 05:28
1

You can't list the content resources - see List content files in a windows phone 7 app?. The workaround is to hardcode the list in your program.

To load the image see the examples under Application.GetResourceStream

Community
  • 1
  • 1
Damian
  • 4,723
  • 2
  • 32
  • 53