Exemple #1
0
        /// <summary>
        /// Adds a weak event listener for a CollectionChanged event.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="handler">The event handler.</param>
        /// <exception cref="ArgumentNullException">source must not be <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">handler must not be <c>null</c>.</exception>
        protected void AddWeakEventListener( INotifyCollectionChanged source, NotifyCollectionChangedEventHandler handler )
        {
            if ( source == null )
                throw new ArgumentNullException( "source" );

            if ( handler == null )
                throw new ArgumentNullException( "handler" );

            CollectionChangedEventListener listener = collectionChangedListeners.LastOrDefault( ( l ) => l.Source == source && l.Handler == handler );

            if ( listener == null )
                listener = new CollectionChangedEventListener( source, handler );
            else
                return;

            collectionChangedListeners.Add( listener );
            CollectionChangedEventManager.AddListener( source, listener );
        }