예제 #1
0
        public void GetIndex_FirstLeafInTree_ReturnsCorrectIndex()
        {
            CreateThreeLevelTree(3);

            int index = _target.GetIndex(_leaves[0]);

            Assert.AreEqual(0, index);
        }
        public void OnSubCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            IList <TResult> collection = (IList <TResult>)sender;

            var nodesForCollection = _collectionToNode[collection];

            for (int i = 0; i < nodesForCollection.Count; i++)
            {
                _collectionIndex.UpdateItemsInNode(nodesForCollection[i], collection.Count);
            }

            if (nodesForCollection.Count == 1)
            {
                var nodeForCollection   = _collectionToNode[collection][0];
                int indexOfNodeInOutput = _collectionIndex.GetIndex(nodeForCollection);
                switch (args.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    FireAddList(args.NewItems, indexOfNodeInOutput + args.NewStartingIndex);
                    break;

#if !SILVERLIGHT
                case NotifyCollectionChangedAction.Move:
                    FireMove(args.NewItems, indexOfNodeInOutput + args.NewStartingIndex, indexOfNodeInOutput + args.OldStartingIndex);
                    break;
#endif
                case NotifyCollectionChangedAction.Remove:
                    FireRemoveList(args.OldItems, indexOfNodeInOutput + args.OldStartingIndex);
                    break;

                case NotifyCollectionChangedAction.Replace:
                    FireReplaceList(args.NewItems, args.OldItems, indexOfNodeInOutput + args.NewStartingIndex);
                    break;

                case NotifyCollectionChangedAction.Reset:
                    FireReset();
                    break;
                }
            }
            else
            {
                FireReset();
            }
        }