/// <summary> /// Sets the <see cref="BehaviourCollection"/> associated with a specified object. /// </summary> /// <param name="dependencyObject">The <see cref="DependencyObject"/> on which to set the <see cref="BehaviourCollection"/>.</param> /// <param name="value">The <see cref="BehaviourCollection"/> associated with the object.</param> /// <exception cref="ArgumentNullException">Parameter <paramref name="dependencyObject"/> is null</exception> public static void SetBehaviours(DependencyObject dependencyObject, BehaviourCollection value) { if (dependencyObject == null) { throw new ArgumentNullException(nameof(dependencyObject)); } dependencyObject.SetValue(Interaction.BehavioursProperty, value); }
/// <summary> /// Gets the <see cref="BehaviourCollection"/> associated with a specified object. /// </summary> /// <param name="dependencyObject">The <see cref="DependencyObject"/> from which to retrieve the <see cref="BehaviourCollection"/>.</param> /// <returns>A <see cref="BehaviourCollection"/> containing the behaviors associated with the specified object.</returns> public static BehaviourCollection GetBehaviours(DependencyObject dependencyObject) { var list = dependencyObject.GetValue(Interaction.BehavioursProperty) as BehaviourCollection; if (list == null) { list = new BehaviourCollection(dependencyObject); dependencyObject.SetValue(Interaction.BehavioursProperty, list); } return(list); }
private static void OnTemplateChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { var dt = args.NewValue as InteractionTemplate; if (dt == null) { return; } BehaviourCollection bc = Interaction.GetBehaviours(dependencyObject); // Remove all behaviours first that were assigned by this class bc.RemoveAllTemplateAssignedBehaviours(); // Then let us create a shallow copy of all behaviours foreach (IBehaviour behavior in dt) { bc.Add(behavior.Copy()); } }