MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

ChildChanged not being fired in response to a list changed? #585

Open ajj7060 opened 6 years ago

ajj7060 commented 6 years ago

Question I have a business object which has three child objects, all of which are lists. Each object in the list does have some common properties, and its possible to work with them while ignoring the objects differences.

To allow editing in a common fashion, there's a forth "child" list/info classes which act as a façade around the other three. To this end, when the façade list is created, it listens to the other three lists' ChildChanged event. If the event indicates a collection/list changed, it responds (we're in WinForms, so the lists are bindinglists, and listchanged is the event that matters most). For instance, if we get a ListChanged event with ItemAdded, we need to create a façade info object and add it to the façade list.

My issue is that for some reason while the ListChanged on the child list is firing, its not resulting in the ChildChanged event firing. It used to listen to the ListChanged directly, however I'm porting the code to work with Xamarin, and listening for ChildChanged simplifies the resulting code.

Is there anything known that might cause ListChanged events not to also result in ChildChanged events for lists? I tried a separate project to reproduce the issue, but the ChildChanged fires as expected there, so I assume something is going wrong, but I'm having trouble tracking down exactly what that is.

Version and Platform CSLA version: 4.6.300 OS: Windows Platform: WinForms

rockfordlhotka commented 6 years ago

You are right, the ChildChanged event should flow up the object graph naturally as you are seeing in your separate project.

I recently did have a conversation with someone using CSLA, where they had a reference to a child and didn't see the event. In their case though, the child had a parent, and the event flowed to the parent - they just wanted it to also flow to a non-parent (a cousin maybe?) and that's not the way it works.

ajj7060 commented 6 years ago

I'm at a loss as to why it isn't working in my actual solution though. In the end I was able to determine that my efforts to port the code in question to work under Xamarin did not break this (it is broken in the revision before I started this work), so as a work around if running under .Net framework I also hook into the ListChanged event.

rockfordlhotka commented 6 years ago

Is your real app on the same runtime as the working test?

ajj7060 commented 6 years ago

Yes, both the test and my real app are running under .Net Framework 4.6.2.

rockfordlhotka commented 6 years ago

So it works in Xamarin/mono, but not in full .NET. That's a start anyway.

ajj7060 commented 6 years ago

Sorry for the confusion; it works in full .Net in a separate project I created to try and isolate the problem, it just doesn't work in my actual real code base (also full .Net).

The reason I moved from ListChanged to ChildChanged to begin with was because I was porting the code to work on Xamarin, and it looked like handling ChildChanged would be simpler (just one event handler), but then I found (for some reason) it didn't fire.

So I created a clean solution to see what might be causing it, and I couldn't get it to break :-)