ObservableCollection and WPF

Posts   
 
    
zinovate
User
Posts: 2
Joined: 25-Jan-2009
# Posted on: 01-Feb-2009 19:39:34   

I am working on a WPF application using the MVVM pattern that depends on WPF's rich databinding. It uses the "ObservableCollection" to expose collections from the ViewModel (Presenter) to the view. In your ViewModel class, you modify the collections directly and use WPF's databinding to update the view.

The collections in LLBLGen don't seem to support the ObservableCollection and requires us to use .ToList() to use and LLBLGen collecions.

I have looked all over for more info on LLBLGens observable collection support with little luck.

Does LLBLGen support ObservableCollections? Is there a way to convert an IEntityCollection2 into an ObservableCollection.

I am glad to see that the Entity objects support INotifyChanged but that's only part of the issue for me.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 02-Feb-2009 10:54:24   

WPF should work with the IBindingList interface, which is implemented on the entityview (the object bound to the control when you bind an entity collection).

May I ask, which LLBLGen Pro runtime library version are you using?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 03-Feb-2009 10:07:08   

To elaborate a bit more: the reason the collection doesn't implement the interface is because that would require a reference to a .NET 3.0 assembly which would mean we would have to have two builds for the same code: one for .NET 2.0 and one for .NET 3.0+, which is rather silly as the interface would be the only true difference and IBindingList and IListSource are already implemented on the objects bound. The interface WPF introduces has 1 extra feature: when an element is removed the event contains the removed element, which isn't the case with IBindingList (which raises ListChanged but that contains only an index of an element which isn't there anymore).

It's not as bad as it looks though: deletes raise a ListChanged reset which should be enough for bound controls. Implementing the interface yourself on the entityview is a bit tricky as the code which manages index updates isn't extensible at the moment.

Frans Bouma | Lead developer LLBLGen Pro