I'm calling SaveItem in DynamicListBase and seeing some incorrect (i think) behaviour.
I'm using CSLA.NET 4.0.0 with WPF. I've set RaiseReplaceEvents to true, and I've tried this binding to a ListView and an Infragistics XamDataGrid.
The first problem I had was that exceptions were being thrown in both the controls when OnCollectionChanged is called. I dug into this a bit and discovered that this was because the item had already been replaced. It turns out this is because ObservableCollection<T>.SetItem had also called OnCollectionChanged, just before it is called by CSLA. Removing this 2nd call seems to do the trick and solves the problem for both controls.
The second problem is that having done this, I noticed I was no longer receiving ChildChanged events when modifying items I had already saved. An inspection of the code showed that while ObvservableBindingList overrides AddItem and RemoveItem to add and remove event hooks, it does not override SetItem to remove hooks from the old item, and add them to the new one.
I added this bit of code to ObservableBindingList to solve this problem:
protected override void SetItem(int index, T item)
Am I correct in my assessment of these issues, and have I gone about fixing them in the right way, or could my changes have some unintended side effects?
The best test is to ensure that the object works with the Silverlight DataGrid control from Microsoft.
I don't own all the third party controls out there, and wouldn't have time to test against them if I did. So I only establish that things work against the Microsoft DataGrid controls.
Unfortunately the Microsoft WPF control is horrible, and just doesn't work right. So I've never been able to establish a baseline for WPF.
But the Silverlight Microsoft control is great, and so I know that the code works in that setting (or at least I believe it works - this can be some tricky stuff).
If your changes make this other WPF datagrid work without breaking the Microsoft Silverlight DataGrid control, or any of the .NET or SL unit tests for CSLA - then it is probably a fine change, and something that should be changed in CSLA.
Thanks for the reply.
I've been looking into this a bit more, and tried running it with these fixes against the Microsoft Datagrid, and it seems to work fine - I'm not sure if there are other problems with it too. I hacked up a quick WPF app to demonstrate it crashing without the fixes, and running fine with them, which I've attached (see readme.txt for more details).
I'm afraid that I don't really have any Silverlight experience though. There shouldn't be a problem with the first fix (removing the OnCollectionChanged call), because this occurs in the #ELSE of a #IF SILVERLIGHT block. The spare half hour I spent messing around with it wasn't really enough to get it up and running to test the ChildChanged fix, but I can't see any obvious reason that it would cause problems, as it's already firing those events before you save it.
I briefly tried running the unit tests, and .NET ones seemed to pass, but I had some issues getting the SL ones to run at all.
I realise this isn't entirely helpful, but I'm afraid I don't have a lot of time to spend getting up to speed with the SL side of this at the moment.
Copyright (c) Marimer LLC