WPF collections and observableCollections

WPF collections and observableCollections

Old forum URL: forums.lhotka.net/forums/t/4584.aspx


Elizabeth posted on Saturday, March 29, 2008

Hi, I'm hoping someone can point me in the right direction here.

I'm working on my first CSLA project, I'm createing the csla objects (version 3.0.3). The GUI is being done by another person, they've asked that I make all my CSLA collections (businessBaseLilst<>) objects implement observableCollection. They've wrapped my current objects in a wrapper that inhertits from observableCollection for the time being. They say this is to make the lists work otherwise they do not do not function correctly (highlighting acts oddly, grid doesn't update properly).  I have read the CSLA 3.0 eBook and I didn't see anything mentioned about collections having to inherit/implement ObservableCollection. We are using infragistics, .netAdvantage wpf controls, the grid in particular.  I've searched here and at infragistics and google and I can find nothing about CSLA and the observableCollection.

Has anyone else had this issue? or anything similar
In case my question was lost was not clear .... do I need to modify my CSLA list objects to implement the observableCollection for the objects to function correctly in WPF?

Thanks

RockfordLhotka replied on Sunday, March 30, 2008

WPF works with lists that implement either IBindingList (BindingList<T>) or INotifyCollectionChanged (ObservableCollection<T>).

CSLA lists implement IBindingList so the objects work not only with WPF, but also with Web Forms, Windows Forms, etc.

You can't implement both interfaces - that confuses WPF terribly, because it honors both of them.

If they really need INotifyCollectionChanged they should be able to create a wrapper that translates the ListChanged event from IBindingList into the CollectionChanged event from INotifyCollectionChanged. Not that I've tried this, but it seems like it would be practical.

Elizabeth replied on Wednesday, April 02, 2008

Thanks for the info.

I'm emberassed to say that I forgot a rather important fact. The problems only start when the user adds more than 2 new items to the list. The new items being added to the list all the same ID. This does not appear to be a problem with WinForms (else my my tests are really bad). Modified adding new items to the list so that the new items have unique ids (-1, -2, etc) and this solves the problem in wpf.

I'm suprised that winforms and wpf don't behave the same. Either that or my test were crap.

Can anyone shed some light on this for me. I've searched but have not found an answer. There was a refrence made to the faq in the wiki, but I didn't find anything on uniqueIds or datagrids.

RockfordLhotka replied on Wednesday, April 02, 2008

WPF uses equality differently than any previous Microsoft technology – which triggered a change in CSLA 3.5 where GetIdValue() is no longer used to determine equality between objects (and thus is now optional). I blogged about this a while back – logical equality and WPF simply don’t mix.

 

Rocky

 

 

From: Elizabeth [mailto:cslanet@lhotka.net]
Sent: Wednesday, April 02, 2008 9:46 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] WPF collections and observableCollections

 

Thanks for the info.

I'm emberassed to say that I forgot a rather important fact. The problems only start when the user adds more than 2 new items to the list. The new items being added to the list all the same ID. This does not appear to be a problem with WinForms (else my my tests are really bad). Modified adding new items to the list so that the new items have unique ids (-1, -2, etc) and this solves the problem in wpf.

I'm suprised that winforms and wpf don't behave the same. Either that or my test were crap.

Can anyone shed some light on this for me. I've searched but have not found an answer. There was a refrence made to the faq in the wiki, but I didn't find anything on uniqueIds or datagrids.


Copyright (c) Marimer LLC