views:

955

answers:

3

I've got a potentially rather large list of objects I'd like to bind to a ListBox in WPF. However, I'd like to have the List load itself incrementally. How can I bind a ListBox to an IEnumerable that loads itself on-demand in such a way that the listbox only tries to enumerate as much as it needs for the display?

A: 

With winform, "virtual mode" - but AFAIK, this isn't the same in WPF. You could see this MSDN forum post.

I largely agree with Drew Marsh - let the user filter the data, rather than scroll through it.

Marc Gravell
That's not the right approach for this app. The user will still be able to filter ans sort, but it will be constrained by a graph structure that has to remain intact.
Ben Collins
+1  A: 

You could store the list in a database - maybe an in-memory one - and then retrieve the needed chunk in your IEnumerable using LINQ.

Boyan
That's a pretty good suggestion, except I'm trying to avoid having everything in memory, not just in the UI.
Ben Collins
Then you can store the data in a full-blown database and retrieve it as needed with LINQ to SQL.
Boyan
+1  A: 

WPF ListBox's use a VirtualizingStackPanel as the layout control for its items. You can set the VirtualizingStackPanel to only load items as needed with the following XAML:

<ListBox 
    VirtualizingStackPanel.IsVirtualizing="True"
    ItemSource="..."
    />
Cameron MacFarland