I have an IEnumerable<> which lazy loads it's data. I want to just set a Combobox's ItemsSource to the IEnumerable, but when I do it goes and loads all the data anyway (which removes the point of lazy loading).
I've tried it with Linq-To-Sql as well since it seems to be a similar theory and it also loads all the data.
Is there an easy way to do this?
Try setting the IsAsync-Property in the ItemsSource-Binding of the ComboBox to True:
<ComboBox ItemsSource={Binding YourItemsSourceProperty, IsAsync=True}
SelectedItem={Binding YourSelectionProperty} />
If that does not change anything, have a look at this one: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/3d343489-90c4-4bdc-8bd9-1046ec9daf76 Maybe you will need to use IList instead.
Alternatively, you could use PriorityBinding, to fill the list with some temporary data until the final list is completely loaded.
Don't bind the control to the IEnumerable directly. Instead, bind it to a ObservableCollection (which is empty at the beginning.) Meanwhile, still do your lazy loading on the IEnumerable as usual (either triggered by drop down combobox or something else.) While the data is loaded or when you have enough data, add the items to that ObservableCollection to populate the comboBox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With