I have been working with the latest CSLA.NET 4 (svn repository) and Rocky's lightweight MVVM framework. I have run into an issue that seems odd to me. Everything (i.e. save, cancel, etc.) works well if I have an editable root and one viewmodel (Rocky's ViewModel).
However, let's say I have an editable root with an editable child (e.g. Invoice, InvoiceItem). My view has two user controls. One user control is assoicated with the edtiable root and has a viewmodel. Another user control is associated with the editable child and also has a viewmodel. Something weird happens to the edit level on the editable child. It seems that the edit level is incremented for each viewmodel I have. Thus, the editable child's edit level=2 before "anything" is done to it whereas the edit level of the root is 1. This causes problems because I can't save or cancel the child object. Instead, if I only have one viewmodel supporting both user controls, everything works well and the edit level = 1.
This isn't a big problem because I can work around it by having one view model support all user controls in the view. However, my actual editable root has many child collections and child objects and the viewmodel is rapidly becoming very complex.
I would like to know if it is by design that every viewmodel increments the editlevel by one. Is there a way to prevent the edit level from being incremented? What is the best practice of how many view models to have per user control (view)? I have been over the code and I don't think it is user error :-). In my debugging efforts I have been able to detect that when the object leaves the dataportal the edit level is zero. But, when it is loaded in the view model (i.e. Refresh) the edit level is incremented.
Any insight would be greatly appreciated. Best regards,
ViewModelBase defaults to ManageObjectLifeTime="true". For a child viewmodel you probably want that to be false, which will prevent the viewmodel from automatically incrementing the child edit level.
Bless you! That is good to know :-) ... I really did want to be able to split out my viewmodels. I really do appreciate your response!
This is the answer of my question http://forums.lhotka.net/forums/p/8972/42680.aspx#42680 in separate viewmodel and why I didn't find problem after changing 1 viewmodel. I appreciate both of you.
When I bind CRUD button with child viewmodel's Can_ properties and click addnew button, then addnew button should be disabled state because added child is invalid at first ,but it isn't. CanAddnew tells false but button's disability not changed. Have you encountered this problem ? Pls read my question in above link. Because of this problem and simplicity as I did in SCSF, I am sticking to 1 viewmodel as far as one view model is enough even in parent-child senario. With 1 viewmodel, I added Can_ poperties same with ViewModelBase but for childviewmodel and can control button's enability via ChildChanged event. If you have more elegant way or I miss something pls advise me. Thank you in advance.
Copyright (c) Marimer LLC