In my Silverlight application, I load all the images I need at application start and store them in a dictionary.
Then as I need them I pick them out of the dictionary and attach them in XAML trees etc.
However, I have the problem that if I attach an Image object to a Grid, then want to use that image again, it tells me:
The image element is already a child
of another element.
How can I run through my dictionary and “detach all images from parent XAML elements”?
Instead of holding a dictionary of
Imagecontrols hold a dictionary ofImageSourceinstead. A single instance of anImageSourcecan be assigned to multiple toImagecontrols.However I suspect that creating an ImageSource on its own will not download the actual file until there is a demand. If that is the case your initialiser would still need to create a list of images that use these images sources and wait for all to indicate they have loaded. Then you could keep a dictionary of
ImageSourceand discard the list of actualImagecontrols.