Beispiel #1
0
        private void ResetChildListener(INotifyPropertyChanged item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            RemoveItem(item);

            ChangeListener listener = null;

            // Add new
            if (item is INotifyCollectionChanged)
            {
                listener = new CollectionChangeListener(_value, item as INotifyCollectionChanged, propertyName, base.propsToIgnore);
            }
            else
            {
                listener = new ChildChangeListener(item as INotifyPropertyChanged, base.propsToIgnore);
            }

            listener.PropertyChanged       += listener_PropertyChanged;
            listener.DeepCollectionChanged += Listener_DeepCollectionChanged;
            _collectionListeners.Add(item, listener);
            RaiseDeepCollectionChanged(_parent, propertyName, item, null);
            listener.Subscribe();
        }
Beispiel #2
0
        /// <summary>
        /// Resets known (must exist in children collection) child event handlers
        /// </summary>
        /// <param name="propertyName">Name of known child property</param>
        private void ResetChildListener(string propertyName)
        {
            if (_childListeners.ContainsKey(propertyName))
            {
                // Unsubscribe if existing
                if (_childListeners[propertyName] != null)
                {
                    _childListeners[propertyName].PropertyChanged       -= new PropertyChangedEventHandler(child_PropertyChanged);
                    _childListeners[propertyName].DeepCollectionChanged -= ChildChangeListener_DeepCollectionChanged;

                    // Should unsubscribe all events
                    _childListeners[propertyName].Dispose();
                    _childListeners[propertyName] = null;
                }

                var property = _type.GetProperty(propertyName);
                if (property == null)
                {
                    throw new InvalidOperationException(string.Format("Was unable to get '{0}' property information from Type '{1}'", propertyName, _type.Name));
                }

                object newValue = property.GetValue(_value, null);

                // Only recreate if there is a new value
                if (newValue != null)
                {
                    if (newValue is INotifyCollectionChanged)
                    {
                        _childListeners[propertyName] =
                            new CollectionChangeListener(_value, newValue as INotifyCollectionChanged, propertyName, propsToIgnore);
                    }
                    else if (newValue is INotifyPropertyChanged)
                    {
                        _childListeners[propertyName] =
                            new ChildChangeListener(newValue as INotifyPropertyChanged, propertyName, propsToIgnore);
                    }

                    if (_childListeners[propertyName] != null)
                    {
                        _childListeners[propertyName].PropertyChanged       += new PropertyChangedEventHandler(child_PropertyChanged);
                        _childListeners[propertyName].DeepCollectionChanged += ChildChangeListener_DeepCollectionChanged;
                        _childListeners[propertyName].Subscribe();
                    }
                }
            }
        }