/// <summary> /// Provides way to set behavior property. /// </summary> /// <param name="dependencyObject">Instance of dependency object.</param> /// <param name="behaviorBindingCollection">Behavior binding collection.</param> private static void SetBehaviors(DependencyObject dependencyObject, BehaviorBindingCollection behaviorBindingCollection) { if (null == dependencyObject || null == behaviorBindingCollection) { return; } dependencyObject.SetValue(BehaviorsPropertyKey, behaviorBindingCollection); INotifyCollectionChanged behaviorBindingCollectionCasted = behaviorBindingCollection; behaviorBindingCollectionCasted.CollectionChanged += OnCollectionChanged; }
// ReSharper restore StaticFieldInitializersReferesToFieldBelow /// <summary> /// Gets behaviors property. /// </summary> /// <param name="dependencyObject">Instance of dependency object.</param> /// <returns>Returns behavior binding collection.</returns> // ReSharper disable ReturnTypeCanBeEnumerable.Global public static BehaviorBindingCollection GetBehaviors(DependencyObject dependencyObject) // ReSharper restore ReturnTypeCanBeEnumerable.Global { if (null == dependencyObject) { throw new InvalidOperationException("Dependency object trying to attach to is set to null"); } var behaviorBindingCollection = dependencyObject.GetValue(BehaviorsProperty) as BehaviorBindingCollection; if (null == behaviorBindingCollection) { // ReSharper disable UseObjectOrCollectionInitializer behaviorBindingCollection = new BehaviorBindingCollection(); // ReSharper restore UseObjectOrCollectionInitializer behaviorBindingCollection.Owner = dependencyObject; SetBehaviors(dependencyObject, behaviorBindingCollection); } return(behaviorBindingCollection); }