private void TriggerActionCollection_VectorChanged(IObservableVector <DependencyObject> sender, IVectorChangedEventArgs eventArgs)
        {
            if (eventArgs.CollectionChange == CollectionChange.Reset)
            {
                foreach (IBehavior behavior in _oldCollection)
                {
                    if (behavior.AssociatedObject != null)
                    {
                        behavior.Detach();
                    }
                }

                _oldCollection.Clear();

                foreach (DependencyObject newItem in this)
                {
                    _oldCollection.Add(VerifiedAttach(newItem));
                }

                return;
            }

            int eventIndex = (int)eventArgs.Index;
            DependencyObject changedItem = this[eventIndex];

            switch (eventArgs.CollectionChange)
            {
            case CollectionChange.ItemInserted:
                _oldCollection.Insert(eventIndex, VerifiedAttach(changedItem));

                break;

            case CollectionChange.ItemChanged:
                IBehavior oldItem = _oldCollection[eventIndex];
                if (oldItem.AssociatedObject != null)
                {
                    oldItem.Detach();
                }

                _oldCollection[eventIndex] = VerifiedAttach(changedItem);

                break;

            case CollectionChange.ItemRemoved:
                oldItem = _oldCollection[eventIndex];
                if (oldItem.AssociatedObject != null)
                {
                    oldItem.Detach();
                }

                _oldCollection.RemoveAt(eventIndex);
                break;

            default:
                Debug.Assert(false, "Unsupported collection operation attempted.");
                break;
            }
        }
예제 #2
0
        private void BehaviorCollection_VectorChanged(IObservableVector <DependencyObject> sender, IVectorChangedEventArgs eventArgs)
        {
            if (eventArgs.CollectionChange == null)
            {
                foreach (IBehavior current in this.oldCollection)
                {
                    if (current.AssociatedObject != null)
                    {
                        current.Detach();
                    }
                }
                this.oldCollection.Clear();
                foreach (DependencyObject dependencyObject in this.AsEnumerable())
                {
                    this.oldCollection.Add(this.VerifiedAttach(dependencyObject));
                }
                return;
            }

            int index             = (int)eventArgs.Index;
            DependencyObject item = this[index];

            switch (eventArgs.CollectionChange)
            {
            case CollectionChange.ItemInserted:
                this.oldCollection.Insert(index, this.VerifiedAttach(item));
                return;

            case CollectionChange.ItemRemoved:
            {
                IBehavior behavior = this.oldCollection[index];
                if (behavior.AssociatedObject != null)
                {
                    behavior.Detach();
                }
                this.oldCollection.RemoveAt(index);
                return;
            }

            case CollectionChange.ItemChanged:
            {
                IBehavior behavior = this.oldCollection[index];
                if (behavior.AssociatedObject != null)
                {
                    behavior.Detach();
                }
                this.oldCollection[index] = this.VerifiedAttach(item);
                return;
            }

            default:
                return;
            }
        }
예제 #3
0
        private void UpdateBehavior(DependencyObject host, IBehavior behavior, DependencyPropertyChangedEventArgs propertyChangedEventArgs)
        {
            if (behavior.IsApplicable())
            {
                behavior.Update(propertyChangedEventArgs);
            }
            else
            {
                host.ClearValue(_property);

                behavior.Detach();
            }
        }
예제 #4
0
    private void UpdateBehavior(DependencyObject host, IBehavior behavior)
    {
        if (behavior.IsApplicable())
        {
            behavior.Update();
        }
        else
        {
            host.ClearValue(_property);

            behavior.Detach();
        }
    }
		private void UpdateBehavior(DependencyObject host, IBehavior behavior)
		{
			if(behavior.IsApplicable())
			{
				behavior.Update();
			}
			else
			{
				host.ClearValue(_property);

				behavior.Detach();
			}
		}
예제 #6
0
        /// <summary>
        /// Detaches the collection of behaviors from the <see cref="Microsoft.Xaml.Interactivity.BehaviorCollection.AssociatedObject"/>.
        /// </summary>
        public void Detach()
        {
            foreach (DependencyObject item in this)
            {
                IBehavior behaviorItem = (IBehavior)item;
                if (behaviorItem.AssociatedObject != null)
                {
                    behaviorItem.Detach();
                }
            }

            this.AssociatedObject = null;
            this._oldCollection.Clear();
        }
예제 #7
0
        /// <summary>
        /// Detaches the collection of behaviors from the <see cref="BehaviorCollection.AssociatedObject"/>.
        /// </summary>
        public void Detach()
        {
            foreach (var item in this)
            {
                IBehavior behaviorItem = (IBehavior)item;
                if (behaviorItem.AssociatedObject != null)
                {
                    behaviorItem.Detach();
                }
            }

            AssociatedObject = null;
            _oldCollection.Clear();
        }
예제 #8
0
        private void BehaviorCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs eventArgs)
        {
            if (eventArgs.Action == NotifyCollectionChangedAction.Reset)
            {
                foreach (IBehavior behavior in _oldCollection)
                {
                    if (behavior.AssociatedObject != null)
                    {
                        behavior.Detach();
                    }
                }

                _oldCollection.Clear();

                foreach (var newItem in this)
                {
                    _oldCollection.Add(VerifiedAttach(newItem));
                }
#if DEBUG
                VerifyOldCollectionIntegrity();
#endif
                return;
            }

            switch (eventArgs.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int eventIndex  = eventArgs.NewStartingIndex;
                var changedItem = (IAvaloniaObject)eventArgs.NewItems[0];
                _oldCollection.Insert(eventIndex, VerifiedAttach(changedItem));
            }
            break;

            case NotifyCollectionChangedAction.Replace:
            {
                int eventIndex = eventArgs.OldStartingIndex;
                eventIndex = eventIndex == -1 ? 0 : eventIndex;

                var changedItem = (IAvaloniaObject)eventArgs.NewItems[0];

                IBehavior oldItem = _oldCollection[eventIndex];
                if (oldItem.AssociatedObject != null)
                {
                    oldItem.Detach();
                }

                _oldCollection[eventIndex] = VerifiedAttach(changedItem);
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                int eventIndex  = eventArgs.OldStartingIndex;
                var changedItem = (IAvaloniaObject)eventArgs.OldItems[0];

                IBehavior oldItem = _oldCollection[eventIndex];
                if (oldItem.AssociatedObject != null)
                {
                    oldItem.Detach();
                }

                _oldCollection.RemoveAt(eventIndex);
            }
            break;

            default:
                Debug.Assert(false, "Unsupported collection operation attempted.");
                break;
            }
#if DEBUG
            VerifyOldCollectionIntegrity();
#endif
        }