Search code examples
windows-phone-7embedded-resourceresourcemanager

Loading images from a directory inside XAP


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?


Solution

  • 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.