/// <summary>
        /// Called when the target object raises the <see cref="INotifyCollectionChanged.CollectionChanged"/> event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method is public to allow the usage of the <see cref="WeakEventListener"/>, do not call this method yourself.
        /// </remarks>
        public void OnObjectCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.OldItems != null)
            {
                foreach (var item in e.OldItems)
                {
                    UnsubscribeNotifyChangedEvents(item);
                }
            }

            // Reset requires our own logic
            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                UpdateCollectionSubscriptions((ICollection)sender);
            }

            if (e.NewItems != null)
            {
                foreach (var item in e.NewItems)
                {
                    SubscribeNotifyChangedEvents(item, true);
                }
            }

            CollectionChanged.SafeInvoke(sender, e);
        }
Esempio n. 2
0
        /// <summary>
        /// Called when the target object raises the <see cref="INotifyCollectionChanged.CollectionChanged"/> event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method is public to allow the usage of the <see cref="WeakEventListener"/>, do not call this method yourself.
        /// </remarks>
        public void OnObjectCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.OldItems != null)
            {
                foreach (var item in e.OldItems)
                {
                    UnsubscribeNotifyChangedEvents(item);
                }
            }

            // Reset requires our own logic
            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                var enumerable = sender as IEnumerable;
                if (enumerable != null)
                {
                    UpdateCollectionSubscriptions(enumerable);
                }
                else
                {
                    Log.Warning("Received NotifyCollectionChangedAction.Reset for '{0}', but the type does implement IEnumerable", sender.GetType().GetSafeFullName());
                }
            }

            if (e.NewItems != null)
            {
                foreach (var item in e.NewItems)
                {
                    SubscribeNotifyChangedEvents(item, true);
                }
            }

            CollectionChanged.SafeInvoke(sender, e);
        }
Esempio n. 3
0
        /// <summary>
        /// Called when the target object raises the <see cref="INotifyCollectionChanged.CollectionChanged"/> event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method is public to allow the usage of the <see cref="WeakEventListener"/>, do not call this method yourself.
        /// </remarks>
        public void OnObjectCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.OldItems != null)
            {
                foreach (var item in e.OldItems)
                {
                    UnsubscribeNotifyChangedEvents(item);
                }
            }

            if (e.NewItems != null)
            {
                foreach (var item in e.NewItems)
                {
                    SubscribeNotifyChangedEvents(item, true);
                }
            }

            CollectionChanged.SafeInvoke(sender, e);
        }
Esempio n. 4
0
        /// <summary>
        /// Called when the target object raises the <see cref="INotifyCollectionChanged.CollectionChanged"/> event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method is public to allow the usage of the <see cref="WeakEventListener"/>, do not call this method yourself.
        /// </remarks>
        public void OnObjectCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            var collection = sender as ICollection;

            lock (_lockObject)
            {
                if (e.OldItems != null)
                {
                    foreach (var item in e.OldItems)
                    {
                        UnsubscribeNotifyChangedEvents(item, collection);
                    }
                }

                // Reset requires our own logic
                if (e.Action == NotifyCollectionChangedAction.Reset)
                {
                    if (collection != null)
                    {
                        UpdateCollectionSubscriptions(collection);
                    }
                    else
                    {
                        Log.Warning("Received NotifyCollectionChangedAction.Reset for '{0}', but the type does not implement ICollection", sender.GetType().GetSafeFullName(false));
                    }
                }
                else if (e.NewItems != null)
                {
                    foreach (var item in e.NewItems)
                    {
                        SubscribeNotifyChangedEvents(item, collection);
                    }
                }
            }

            CollectionChanged.SafeInvoke(sender, e);
        }
Esempio n. 5
0
 private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     CollectionChanged.SafeInvoke(this, e);
 }
Esempio n. 6
0
 public void RaiseCollectionChangedEvent()
 {
     CollectionChanged.SafeInvoke(this, () => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
 }