any help on tracking list position?

any help on tracking list position?

Old forum URL:

Brannon posted on Monday, April 04, 2011

I'm using CSLA 4.1 with all my children inheriting from BusinessBase and lists inheriting from BusinessListBase and using WPF items with CSLA.Xaml.ViewModel.

I've got a situation where I'm rendering items in a list and the items draw differently if they are first, last and/or their header doesn't match the previous item. By "render" I mean that they have a UIElement property. (Am I off on the wrong path already and the owner should draw those items that differ between children?) I would like to bind the corresponding ViewModels for the children to a position in the parent model's list as well as letting them know about the list itself so that they can check properties on siblings. Is that weird or anticipated? Is there some other smarter way to do this with rules and such? Thanks.

RockfordLhotka replied on Tuesday, April 05, 2011

The question you should ask yourself when added a property to a business object like that, is whether this property will be valuable in the following types of interface:

If the property would only apply to one of these, then it should not be in the business class.

The solutions are to make the property more abstract so it can apply to all three, or to use a viewmodel in between the UI and business class to implement this property, or a combination of both.

Brannon replied on Saturday, April 09, 2011

After further thought, what I really want is an Index property on the item that I can bind to. I've got some code below showing how to get the index from the parent property. Please help me make this a registered property (aka, something that triggers OnPropertyChanged). What events on the parent would I subscribe to and when? Or could I do it with some kind of dependency rule?


public class TestParent


public class A : Csla.BusinessBase<A>


public int Index




int idx = -1;

var p = Parent as IList<A>;

if (p != null)


idx = p.IndexOf(this);


return idx;





public class AList : Csla.BusinessListBase<AList, A> { }



public void Go1()


var list = new AList();

var c1 = list.AddNew();

var c2 = list.AddNew();

var c3 = list.AddNew();


Assert.AreEqual(0, c1.Index);

Assert.AreEqual(1, c2.Index);

Assert.AreEqual(2, c3.Index);

Assert.AreEqual(-1, new A().Index);


Copyright (c) Marimer LLC