예제 #1
0
        public void UpdateNumberOfItems_DeepInTree_UpdatesParentNodes()
        {
            CreateThreeLevelTree(1);
            _target.UpdateItemsInNode(_leaves[2], 3);

            Assert.AreEqual(3, _leaves[2].ItemsInNode);
            Assert.AreEqual(4, _leaves[1].Above.ItemsInNode);
            Assert.AreEqual(7, _headers[0].ItemsInNode);
        }
        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();
            }
        }