/// <summary>Sets the behaviors.</summary> /// <param name="window">The window.</param> /// <param name="behaviors">The collection of <see cref="NativeBehavior"/>s.</param> public static void SetBehaviors(Window window, NativeBehaviors behaviors) { if (window == null) { throw new ArgumentNullException("window"); } window.SetValue(NativeBehaviorsProperty, behaviors); }
public static IEnumerable <TBehavior> SelectBehaviors <TBehavior>(Window window) where TBehavior : NativeBehavior { foreach (var behavior in NativeBehaviors.GetBehaviors(window)) { if (behavior is TBehavior) { yield return((TBehavior)behavior); } } }
/// <summary>Gets the behaviors. /// </summary> /// <param name="window">The window.</param> /// <returns></returns> private static NativeBehaviors GetNativeBehaviors(Window window) { if (window == null) { throw new ArgumentNullException("window"); } // This is the plain old normal thing: var behaviors = (NativeBehaviors)window.GetValue(NativeBehaviorsProperty); // Our raison d'être: create a new collection if there isn't one yet if (behaviors == null) { behaviors = new NativeBehaviors(window); } return(behaviors); }