CLSA AddChild Default values

145 Views Asked by At

I'm using CSLA latest release and trying to add a row with default items to the collection. What I've noticed is the default constructor of the Foo class is called instead of the AddNewCore in the FooList Class. I am unable to get the AddNewCore or the Child_Create methods to get invoked when a new row is added in a XamDataGrid row. (A row is added, but it is from the default constructor of the FooLine Class--i.e. no default values and no MarkAsChild attribute.) Here is the code snippet that is in the FooList class:

    protected override FooItem AddNewCore()
    {
        var item = DataPortal.CreateChild<FooItem>();
        MarkAsChild();
        Add(item);
        return base.AddNewCore();
    }

    protected override void Child_Create()
    {
        var item = DataPortal.CreateChild<FooItem>();
        MarkAsChild();
        Add(item);
        base.Child_Create();
    }

What am I doing wrong?

2

There are 2 best solutions below

0
kcabral On

For information: The reason the above code does not work has to do with the way WPF invokes the New method. Typically, in other frameworks it is possible to hook on to that event, intercept it, and return with default data. With WPF, it is necessary to check the RecordAdding, or RecordAdded trigger events and process the invocations by hand.

In my case, the WPF would look like:

  <i:Interaction.Triggers>' 
       i:EventTrigger EventName="RecordAdded">
       <ei:CallMethodAction TargetObject="{Binding}" 
       MethodName="CreateDefaultAddressValuesCommand" />
  </i:EventTrigger>

In the view model:

    var idx = FooInformation.FooAddressList.Count - 1;
    var address = await FooAddress.CreateAsync();            
    FooListing.FooAddressList[idx] = address;
0
Amol On

AddNewCore() method exists in client side CSLA class 'ExtendedBindingList' with 'void' return type and same method is exists in server side class 'ObservableBindingList' with return type 'ListClass'. So we required to call run time client side method from server side. Please refer below code for the same.

    #if SILVERLIGHT
    protected override void AddNewCore()
    {
        var item = DataPortal.CreateChild<FooItem>();
        Add(item);
    }
    #endif