コード例 #1
0
        internal CompositeItemCommandBindingBuilder(
            [NotNull] SourceItemCommandBinding <TSourceItem, TSourceItemValue> sourceItemBinding,
            [NotNull] TargetItemBinding <TTargetItem, TTargetItemValue> targetItemBinding,
            [NotNull] BindingSet <TSourceItem> bindingSet,
            [NotNull] ICompositeItemBinding <TSourceItem> oldCompositeItemBinding)
        {
            _compositeItemBinding = new CompositeItemCommandBinding <TSourceItem, TSourceItemValue, TTargetItem, TTargetItemValue>(
                sourceItemBinding,
                targetItemBinding,
                oldCompositeItemBinding.RequestedBindingMode,
                oldCompositeItemBinding.ValueConverter);

            _bindingSet = bindingSet;
            _bindingSet.Remove(oldCompositeItemBinding);
            _bindingSet.Add(_compositeItemBinding);
        }
        public void Remove_Invoke_CallsListChanged()
        {
            var obj  = new object();
            var list = new List <object> {
                obj
            };
            var bindingList = new BindingSet <object>(list);

            bool calledListChanged = false;

            bindingList.ListChanged += (object sender, ListChangedEventArgs e) =>
            {
                calledListChanged = true;
                Assert.Equal(0, e.NewIndex);
                Assert.Equal(ListChangedType.ItemDeleted, e.ListChangedType);

                // The event is raised after the removal.
                Assert.Equal(0, bindingList.Count);
            };
            bindingList.Remove(obj);

            Assert.True(calledListChanged);
        }
        public void Remove_INotifyPropertyChangedItems_RemovesPropertyChangedEventHandlers()
        {
            var item        = new Item();
            var bindingList = new BindingSet <Item> {
                item
            };

            Assert.Equal(1, item.InvocationList.Length);

            bool calledListChanged = false;

            bindingList.ListChanged += (object sender, ListChangedEventArgs e) =>
            {
                calledListChanged = true;
                Assert.Equal(ListChangedType.ItemDeleted, e.ListChangedType);
                Assert.Equal(0, e.NewIndex);
            };

            bindingList.Remove(item);
            Assert.True(calledListChanged);
            Assert.Empty(bindingList);
            Assert.Null(item.InvocationList);
        }