CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Refresh ReadOnlyList after edit

rated by 0 users
Not Answered This post has 0 verified answers | 6 Replies | 4 Followers

Top 500 Contributor
36 Posts
t.kehl posted on Sat, Aug 7 2010 9:19 AM

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

All Replies

Top 100 Contributor
80 Posts

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

Top 10 Contributor
9,282 Posts

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.

Rocky

Top 25 Contributor
461 Posts

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 Freitas Leal, CslaGenFork (Open Source CSLA code generator)

Not Ranked
12 Posts

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 :-(

Top 25 Contributor
461 Posts

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

Tiago Freitas Leal, CslaGenFork (Open Source CSLA code generator)

Page 1 of 1 (7 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems