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)); }
protected virtual void Unsubscribe() { Group?.Behaviors.Remove(this); Group = null; }