I have lots of images stored in isolated storage and want to display them in a listbox. However, I don't want all images to be loaded right away but lazily. So only when the user scrolls to see new items the images should be loaded. I also want to use data binding for providing the list item's data and image.
In the tests I did all images always got loaded right away and at once, so I am unsure whether this lazy loading can be achieved with the default ListBox
and data binding. Can it?
Check this LazyListBox implementation. This ListBox will load complex template for items visible on screen. For items not visible on screen you set simple template.
You can use the standard ListBox to "lazy load" your items with databinding. The keyword here is "data virtualization". You have to implement IList to the class you want to databind. The indexer method will only be called for the items currently visible and for the next calculated ~2 screens. This is also the reason you should use a fixed size grid for your item-layout, not a stackpanel with a calculated height based on all containing items (performance!).
You don't have to implement all IList members, just a few. Here is an example:
While debugging you can see that not all items are loaded at once but only when needed (see Debug.WriteLine()).