public void ReplaceItems_CallsHandleChangeWithCollectionPopulatedArgs()
        {
            var oldItems = new[] { CreateItem(), CreateItem() };
            var newItems = new[] { CreateItem() };

            Collection.Add(oldItems[0]);
            Collection.Add(oldItems[1]);

            ResetStub();
            IVMCollection <IViewModel> c = Collection;

            c.ReplaceItems(newItems, null);

            AssertChangeArgs(
                CollectionChangedArgs <IViewModel> .CollectionPopulated(Collection, oldItems)
                );
        }
コード例 #2
0
        /// <inheritdoc />
        void IVMCollection <TItemVM> .ReplaceItems(IEnumerable <TItemVM> newItems, IChangeReason reason)
        {
            TItemVM[] oldItems = this.ToArray();

            try {
                IsPopulating = true;
                Clear();
                newItems.ForEach(Add);

                // We have to call the behaviors BEFORE we raise the ListChanged event. The
                // behavior chain does essential initialization (e.g. sets the descriptor).
                // If we raise the ListChanged before, the UI may try to access the VMs before
                // they are properly initialized.
                CallBehaviors(CollectionChangedArgs <TItemVM> .CollectionPopulated(this, oldItems, reason));
            } finally {
                IsPopulating = false;
            }
        }
        protected void HandleCollectionPopulated(TItemVM[] previousItems)
        {
            var args = CollectionChangedArgs <TItemVM> .CollectionPopulated(Collection, previousItems);

            Behavior.HandleChange(Context, args);
        }