Tracking Expressions

Sep 9, 2009 at 3:21 PM

I have another question wrt to the implementation though.

  1. Is it possible to track Distincts on a particular property within observablecollection<T>. Say I need to bind distincts of Person.Name within the the collection and bind to a dropdownlist.
  2. Is it possible to track Expressions based out of a calculation on properties. E.g. Savings = (Person.Income * 30%) - Person.Expense and bind it to a control or a column in a datagrid.

I am sure this is what you intended with this api, but a guidance in the implementation approach will be very helpful.

Thanks for your help


Sep 9, 2009 at 4:10 PM

Hi Vinay,

Yes, both are very possible:

For the first you can use the standard Enumerable.Distinct method like:

    persons => persons.Select( p => p.Name ).Distinct()

The Cascade method will return an IEnumerable<string> provided Name is of type string.

For the second just use the expression you want:

    person => person.Income * 0.3 - person.Expense

And bind to the Value property of the returned IValueProvider. Income and Expense properties naturaly need to be observable if you want the resulting Value to react to changes. (The owning class needs to implement INotifyPropertyChanged (Silverlight))

If you have a collection of persons:

    persons => 
        from p in persons
        select p.Income * 0.3 - p.Expense

If you feel like donating an Obtics users guide, I would be very interested. :-)






Sep 10, 2009 at 6:49 PM


Thanks for the quick response. I would love to be helpful whereever I could.