CLSA4 ViewModelBase : undo.BeginEdit()

CLSA4 ViewModelBase : undo.BeginEdit()

Old forum URL:

HK.Lee posted on Saturday, May 22, 2010

Hi alI,

How do you design viewmodel in case of parent-child object such as project-projectResouces-Resouce in Projecttracker sample ?  My object is same with project tracker as such;

  Cmod(BusinessBase) - CmodAccessarys(BusinessListBase) - Accessary(BusinessBase)

I created 2 viewmodels, one for root and another for BusinessListBase and bind them through xaml.

        <CollectionViewSource x:Key="cmodViewModelViewSource" d:DesignSource="{d:DesignInstance this:CmodViewModel, CreateList=True}" />
        <this:CmodChildViewModel x:Key="cmodChildVM" Model="{Binding Source={StaticResource cmodViewModelViewSource},Path=Model.CmodAccessarys}"/>

However, when child collection viewmodel is created and reached in ModelProperty's  PropertyMetadata() of ViewModelBase,complained error at undo.BeginEdit() because model is child object. 

 I think 1 viewmodel will cover everything for parent-child relations but  would be very crowded,so 2 would be more cleaner. If I didn't take a wrong way in xaml binding, PropertyMetadata() of viewmodelbase might be changed to consider IsChild status as follows;

    if (viewmodel.ManageObjectLifetime)
              //var undo = e.NewValue as Csla.Core.ISupportUndo;
              //if (undo != null)
              //    undo.BeginEdit();

              var undo = e.NewValue as Csla.Core.ISupportUndo;
              if (undo != null)
                  var parent = e.NewValue as IParent;
                  if (parent == null)

In addition, it might be needed to reset and change  IsEnable of add/delete/cancel buttons according to U.I's special state, in which is already automatically set in viewmodel's SetProperties(). If SetProperties() of ViewModelBase is 'protected virtual', subclassed viewmodel can  have more flexibility.

Thank you in advance.



HK.Lee replied on Monday, May 24, 2010

It looks my faults. Runs fine, so close this thread.

Copyright (c) Marimer LLC