Beispiel #1
0
        /// <summary>
        ///     Fires notification with all accumulated events
        /// </summary>
        /// <param name="reason">True is called by App code. False if called from GC.</param>
        protected virtual void Dispose(bool reason)
        {
            // Fire delayed notifications
            if (null == _notifyInfo || !_notifyInfo.HasEventArgs)
            {
                return;
            }

            if (null != _notifyInfo.RootCollection.PropertyChanged)
            {
                if (_notifyInfo.IsCountChanged)
                {
                    _notifyInfo.RootCollection.OnPropertyChanged(new PropertyChangedEventArgs(CountString));
                }

                _notifyInfo.RootCollection.OnPropertyChanged(new PropertyChangedEventArgs(IndexerName));
            }

            using (_notifyInfo.RootCollection.BlockReentrancy())
            {
                var args = _notifyInfo.EventArgs;

                foreach (var delegateItem in _notifyInfo.RootCollection.CollectionChanged.GetInvocationList())
                {
                    delegateItem.DynamicInvoke(new object[] { _notifyInfo.RootCollection, args });
                }
            }

            // Reset and reuse if necessary
            CollectionChanged = _notifyInfo.Initialize();
        }
        /// <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();
            }
        }