开发者

Silverlight ComboBox bound to IEnumerable<BitmapImage> where images are downloaded from server

开发者 https://www.devze.com 2023-01-31 19:03 出处:网络
I am having an issue with binding a ComboBox to an IEnumerable<BitmapImage>, where the images are stored 开发者_StackOverflowon the server and downloaded on demand. At the time the binding actua

I am having an issue with binding a ComboBox to an IEnumerable<BitmapImage>, where the images are stored 开发者_StackOverflowon 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.


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


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;}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消