예제 #1
0
 /// <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);
 }
예제 #2
0
 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);
         }
     }
 }
예제 #3
0
        void StickyWindow_Loaded(object sender, RoutedEventArgs e)
        {
            AdjustLocation();
            if (loaded)
            {
                return;
            }

            WindowManager.RegisterWindow(this);
            var nativeBehaviors = new NativeBehaviors(this);
            var snapBehavior    = new SnapToBehavior();

            snapBehavior.OriginalForm = this;
            nativeBehaviors.Add(snapBehavior);
            loaded = true;
        }
예제 #4
0
        /// <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);
        }