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
2008-12-08 13:27:29
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
2008-12-08 13:48:46
+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
2008-12-08 13:56:21
That's a pretty good suggestion, except I'm trying to avoid having everything in memory, not just in the UI.
Ben Collins
2008-12-08 14:50:39
Then you can store the data in a full-blown database and retrieve it as needed with LINQ to SQL.
Boyan
2008-12-08 16:28:04
+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
2008-12-08 15:58:03