3

I am having an issue with binding a ComboBox to an IEnumerable<BitmapImage>, where the images are stored on the server and downloaded on demand. At the time the binding actually takes place, most of the images have not downloaded yet and causes the ComboBox to display empty selections in their place. Is there an easy way of forcing the bound images to update as their download completes. I would like to do this asynchronously; i.e., I don't want to wait until they are all downloaded before binding the list to the ComboBox.

All suggestions are welcome, including proposing alternative approaches.

Jeffrey
  • 509
  • 4
  • 11
  • Are you saying the empty selections remain empty after the image download completes? – AnthonyWJones Dec 18 '10 at 18:47
  • Yes, that is exactly what is happening. – Jeffrey Dec 18 '10 at 19:25
  • Have you tried binding it to an ObservableCollection? – TerenceJackson Dec 19 '10 at 12:54
  • I retrieve a list of images to be displayed from the database and create a collection of BitmapImages with their corresponding URL and add them to the collection. The ComboBox is then bound to the collection. ObservableCollection would not help, as I am not making any changes to the collection itself. Besides, I am already implementing INotifyPropertyChanged to let the bindings now when to update if I do make a change to the collection. Thank you though. – Jeffrey Dec 20 '10 at 15:27

2 Answers2

1

I'm experiencing a similar problem. My hacked solution is to set each BitmapImage to a dummy Image control's source. As long as the Image control is visible, it works. Then I just collapse the Image after every BitmapImage was "loaded".

sharoz
  • 6,157
  • 7
  • 31
  • 57
0

I´m working on a similar solution. The way i display images in a combobox and load them on demand is, that i define an Image-Control as DataTemplate and bind the the Source of the Image-Control to the URL of corresponding image file.

This way it´s up to the Image control to load the Image on Demand (when it gets displayed)

XAML:

<ComboBox Items="{Binding Images}">
  <ComboBox.ItemTemplate>
    <DataTemplate>
      <Image Source="{Binding ImageUrl}"/>
    </DataTemplate>
  </ComboBox.ItemTemplate>
</ComboBox>

C#:

public class ImageViewModel{
   public string ImageUrl {get; set;}
}
Jehof
  • 34,674
  • 10
  • 123
  • 155