コード例 #1
0
        /// <summary>
        /// Constructor that configures the container to delay or disable notifications.
        /// </summary>
        /// <param name="parent">Reference to an original collection whos events are being postponed</param>
        /// <param name="notify">Specifies if notifications needs to be delayed or disabled</param>
        public ObservableCollectionEx2(ObservableCollectionEx2 <T> parent, bool notify)
            : base(parent.Items)
        {
            _notifyInfo = new NotificationInfo();
            _notifyInfo.RootCollection = parent;

            if (notify)
            {
                CollectionChanged = _notifyInfo.Initialize();
            }
        }
コード例 #2
0
            public NotifyCollectionChangedEventHandler Initialize()
            {
                _action   = null;
                _newItems = null;
                _oldItems = null;

                return((sender, args) =>
                {
                    ObservableCollectionEx2 <T> wrapper = sender as ObservableCollectionEx2 <T>;
                    Debug.Assert(null != wrapper, "Calling object must be ObservableCollectionEx2<T>");
                    Debug.Assert(null != wrapper._notifyInfo, "Calling object must be Delayed wrapper.");

                    // Setup
                    _action = args.Action;

                    switch (_action)
                    {
                    case NotifyCollectionChangedAction.Add:
                        _newItems = new List <T>();
                        IsCountChanged = true;
                        wrapper.CollectionChanged = (s, e) =>
                        {
                            AssertActionType(e);
                            foreach (T item in e.NewItems)
                            {
                                _newItems.Add(item);
                            }
                        };
                        wrapper.CollectionChanged(sender, args);
                        break;

                    case NotifyCollectionChangedAction.Remove:
                        _oldItems = new List <T>();
                        IsCountChanged = true;
                        wrapper.CollectionChanged = (s, e) =>
                        {
                            AssertActionType(e);
                            foreach (T item in e.OldItems)
                            {
                                _oldItems.Add(item);
                            }
                        };
                        wrapper.CollectionChanged(sender, args);
                        break;

                    case NotifyCollectionChangedAction.Replace:
                        _newItems = new List <T>();
                        _oldItems = new List <T>();
                        wrapper.CollectionChanged = (s, e) =>
                        {
                            AssertActionType(e);
                            foreach (T item in e.NewItems)
                            {
                                _newItems.Add(item);
                            }

                            foreach (T item in e.OldItems)
                            {
                                _oldItems.Add(item);
                            }
                        };
                        wrapper.CollectionChanged(sender, args);
                        break;

#if !SILVERLIGHT
                    case NotifyCollectionChangedAction.Move:
                        _newIndex = args.NewStartingIndex;
                        _newItems = args.NewItems;
                        _oldIndex = args.OldStartingIndex;
                        _oldItems = args.OldItems;
                        wrapper.CollectionChanged = (s, e) =>
                        {
                            throw new InvalidOperationException(
                                "Due to design of NotifyCollectionChangedEventArgs combination of multiple Move operations is not possible");
                        };
                        break;
#endif
                    case NotifyCollectionChangedAction.Reset:
                        IsCountChanged = true;
                        wrapper.CollectionChanged = (s, e) => { AssertActionType(e); };
                        break;
                    }
                });
            }