예제 #1
0
        protected virtual bool Subscribe(Type targetType)
        {
            var target = this.AssociatedObject.GetSelfAndAncestors()
                         .FirstOrDefault(x =>
            {
                var type = x.GetType();
                return((type == targetType) || type.IsSubclassOf(targetType));
            });

            if (target is null)
            {
                return(false);
            }

            var behavior = Interaction.GetBehaviors(target).OfType <IItemBehavior>().FirstOrDefault();

            if (behavior is null)
            {
                return(false);
            }

            Group = behavior.Group ?? new ItemBehaviorGroup();
            return(Group.Behaviors.Add(this));
        }
예제 #2
0
 protected virtual void Unsubscribe()
 {
     Group?.Behaviors.Remove(this);
     Group = null;
 }