Refresh ReadOnlyList after edit

Refresh ReadOnlyList after edit

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


t.kehl posted on Saturday, August 07, 2010

Hi.

I have a WPF Application. In this, there is a Grid which is bound to a ReadOnlyList which contains the items to show. Now, when the user DoubleClick on a Item, I create a EditableRoot-Item which the Id of the item which the User has selected and Show a EditForm. After Editing, the Item will be saved. This is working great. Now, what is the best strategy to update the item in the bounded ReadOnlyList that the Grid is showing the new Values?

Thanks for your Info.

Best Regards, Thomas

JonStonecash replied on Saturday, August 07, 2010

There are two ways that I can think of.  One, re-read the list, and two, add some functionality to the read only business object that allows it to update itself.

The first way, re-reading the list, is simple and easy to do.  Unless there are serious performance issues, this is the way to go.

The second way, bypassing some of the protections of the Csla readonly lists, can be done but it is complicated and is prone to breakage.  If I were to go down this path, I would add a method to the readonly business class that would accept the newly updated editable object and use the LoadProperty methods to change the values.  I am not entirely familiar with WPF, but I would imagine that you could refresh the display by rebinding the list.  Having said all of this, I really would avoid this approach.  This approach breaks the typical patterns within the application.  Someone, down the road, might make a change and not realize that there was this deviation from the pattern.  A lot of time might well be spent trying to track down the cause of the defects arising from this. 

 

Jon Stonecash

tiago replied on Friday, August 13, 2010

Hi Thomas,

Have a look at

http://www.lhotka.net/weblog/IAmWorkingOnMyUsingCSLANET30EbookAndWroteSomeContentThatIDontThinkImGoingToUseInTheBook.aspx

Regards

RockfordLhotka replied on Friday, August 13, 2010

Be careful with that though, as it can cause memory leaks.

To do that correctly you really need to use weak references, or a strict publish/subscribe model.

Having objects handle a static event must be done very carefully or those objects will never leave memory - that static event will always have a reference to the object, so the garbage collector will never reclaim them.

tiago replied on Saturday, August 14, 2010

Hi Rocky,

RockfordLhotka

Be careful with that though, as it can cause memory leaks.

To do that correctly you really need to use weak references, or a strict publish/subscribe model.

Having objects handle a static event must be done very carefully or those objects will never leave memory - that static event will always have a reference to the object, so the garbage collector will never reclaim them.

You're right. I think you are referring to this http://msdn.microsoft.com/en-us/library/system.windows.weakeventmanager.aspx

tiago replied on Tuesday, August 17, 2010

Hi again Rocky,

My test program implements this technique and it works all right with no remoting in place. As soon as I turn remoting on, it doesn't work...

My project was CSLA 3.0.5 but now is CSLA 4.0.1.

I'm under the very strong impression it did work under 3.0.5... must go back and check

jlfernandezmiranda replied on Tuesday, August 17, 2010

How can I implement a weak event  using csla? I need to replace shared static events with weakevent manager? Could you write a sample using vb? I have not found a sample that uses weak event manager :-(

Copyright (c) Marimer LLC