Bindin to nested properties?

Bindin to nested properties?

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


nige posted on Thursday, June 14, 2007

How do we bind to nested properties such as "Address.Street" i know we can use eval to get one way binding using eval("Address.Street") but this doesnt work with Bind for 2-way. What is the suggested approach within csla.

 

 

dcleven replied on Thursday, June 14, 2007

I assume you want to bind a control to a property and the property is a CSLA object that contains another CSLA object, if so you simply use the . (period) between properties.

For example Order object cotains Address which has a street property. Order.Address.street should work just fine, assuming you have a Address property in Order.

--Doug

nige replied on Friday, June 15, 2007

Does that work with 2-way binding? i understood it was only the eval keyword that supported that dot syntax

Skafa replied on Friday, June 15, 2007

This doesn't work with two-way binding.

You need to flatten your object hierarchy to bind to nested object properties.


What I usually do is create a flattened view of the (nested) object structure outside of the domain model (because these views are only used to support binding).

public class UserView {
 private User _user;
 
 public string UserName {
  get {
   return _user.Name;
  }
  set {
   _user.Name = value;
  }
 }
 
public string UserAddressZip {
 get {
  return _user.Address.Zip;
  }
  set {
   _user.Address.Zip = value;
  }
 }
 // etc.
}

ajj3085 replied on Friday, June 15, 2007

One method which I use and found works very well is simply to create a second binding source and set its datasource to the child object.  Then bind controls to that second datasource.

An alternative, if its approperiate for your case, is to have the root BO act as a facade, although it would delegate its calls to the child object.

HTH
Andy

Copyright (c) Marimer LLC