Пример #1
0
            /// <summary>
            ///     Attaches the source.
            /// </summary>
            /// <param name="source">
            ///     The source.
            /// </param>
            protected override void AttachSource(object source)
            {
                base.AttachSource(source);

                if (source != null && source.GetType().ContainsEvent(WeakCollectionBinding.CollectionChangedEventName))
                {
                    if (collectionWeakEvent != null)
                    {
                        collectionWeakEvent.DetachEvent();
                    }

                    if (collectionWeakEvent == null)
                    {
                        collectionWeakEvent = new WeakEvent(this);
                    }

                    collectionWeakEvent.AttachEvent(source, null, WeakCollectionBinding.CollectionChangedEventName, "OnSourceCollectionChanged");
                }
            }
Пример #2
0
        /// <summary>
        ///     UnWatch the source property.
        /// </summary>
        /// <param name="source">
        ///     The source.
        /// </param>
        /// <param name="property">
        ///     The property.
        /// </param>
        /// <returns>
        ///     The <see cref="WeakCommandBinding"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     The source can not be null.
        /// </exception>
        public WeakCommandBinding UnWatch(object source, string property)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var bindSource = new BindContext(source, property);

            var entry = new WeakEntry(null, bindSource.Source, property);

            if (this.watchEvents.ContainsKey(entry))
            {
                WeakEvent watchEvent = this.watchEvents[entry];
                watchEvent.DetachEvent();
                this.watchEvents.Remove(entry);
            }

            this.RaiseCanExecuteChanged();

            return(this);
        }