public void UnapplySetter(AttachedTriggerBase trigger, Setter setter)
        {
            this.bindable.PropertyChanged -= OnBindablePropertyChanged;

            var  lastActiveTrigger = setters.Keys.LastOrDefault(t => t.IsActive);
            bool affectsValue      = lastActiveTrigger != trigger;

            setters[trigger].Remove(setter);
            if (setters[trigger].Count == 0)
            {
                setters[trigger] = null;
            }

            if (affectsValue)
            {
                if (lastActiveTrigger == null)
                {
                    if (setter.OriginalValueBinding != null)
                    {
                        this.bindable.SetBinding(this.property, setter.OriginalValueBinding.Clone());
                    }
                    else
                    {
                        this.bindable.SetValue(this.property, this.originalValue);
                    }
                }
                else
                {
                    setters[lastActiveTrigger].Last().Apply(this.bindable);
                }
            }

            this.bindable.PropertyChanged += OnBindablePropertyChanged;
        }
        public void ApplySetter(AttachedTriggerBase trigger, Setter setter)
        {
            this.bindable.PropertyChanged -= OnBindablePropertyChanged;

            var  lastActiveTrigger = setters.Keys.Last(t => t.IsActive);
            bool affectsValue      = lastActiveTrigger == trigger;

            if (!this.originalValueSet)
            {
                this.originalValue    = this.bindable.GetValue(this.property);
                this.originalValueSet = true;
            }

            if (setters[trigger] == null)
            {
                setters[trigger] = new List <Setter>();
            }

            setters[trigger].Add(setter);

            if (affectsValue)
            {
                setter.Apply(this.bindable);
            }

            this.bindable.PropertyChanged += OnBindablePropertyChanged;
        }
 private void UnapplyTrigger(AttachedTriggerBase triggerToUnapply)
 {
     foreach (var setter in triggerToUnapply.Setters)
     {
         var target           = setter.Target ?? this.attachedObject;
         var valuesByProperty = GetSettersByBindable(target);
         valuesByProperty[setter.Property].UnapplySetter(triggerToUnapply, setter);
     }
 }
        public void RegisterTrigger(AttachedTriggerBase trigger)
        {
            if (setters.ContainsKey(trigger))
            {
                return;
            }

            setters[trigger] = null;
        }
        private void ApplyTrigger(AttachedTriggerBase triggerToApply)
        {
            foreach (var setter in triggerToApply.Setters)
            {
                var target = setter.Target ?? this.attachedObject;
                var setterValueCollections = GetSettersByBindable(target);

                setterValueCollections[setter.Property].ApplySetter(triggerToApply, setter);
            }
        }
        public void UnregisterTrigger(AttachedTriggerBase trigger)
        {
            var settersToUnapply = setters[trigger];

            if (settersToUnapply != null)
            {
                settersToUnapply.ForEach(s => this.UnapplySetter(trigger, s));
            }

            setters.Remove(trigger);
        }