Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lazy Loading wpf Combobox items

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?

like image 562
Chris McGrath Avatar asked Jan 22 '23 00:01

Chris McGrath


2 Answers

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.

like image 59
Simon D. Avatar answered Feb 01 '23 01:02

Simon D.


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.

like image 40
treehouse Avatar answered Feb 01 '23 01:02

treehouse