public virtual void AddChild(CarouselItem i) { i.State.ValueChanged += state => ChildItemStateChanged(i, state.NewValue); i.ChildID = ++currentChildID; if (lastCriteria != null) { i.Filter(lastCriteria); int index = InternalChildren.BinarySearch(i, criteriaComparer); if (index < 0) { index = ~index; // BinarySearch hacks multiple return values with 2's complement. } InternalChildren.Insert(index, i); } else { // criteria may be null for initial population. the filtering will be applied post-add. InternalChildren.Add(i); } }