Пример #1
0
        /// <summary>
        ///     Makes a custom-shaped window draggable based upon clicks on objects with the WindowMovement.DragsWindow attribute.
        /// </summary>
        /// <param name="window">The Window to make draggable.</param>
        /// <returns>true if the operation was successful.</returns>
        private static bool MakeWindowMovable(Window window)
        {
            HwndSource source = GetWindowSource(window);

            if (source == null)
            {
                return(false);
            }

            CaptionHitTester tester;

            if (!RegisteredWindows.TryGetValue(window, out tester))
            {
                // Register a CaptionHitTester for the window
                tester = new CaptionHitTester(window);
                RegisteredWindows[window] = tester;
                window.Closed            += window_Closed;      // Unregisters the window when it's closed
            }

            // Register the CaptionHitTester on the window (this is where the magic happens)
            tester.Hook(source);
            return(true);
        }
Пример #2
0
        /// <summary>
        ///     Makes a custom-shaped window draggable based upon clicks on objects with the WindowMovement.DragsWindow attribute.
        /// </summary>
        /// <param name="window">The Window to make draggable.</param>
        /// <returns>true if the operation was successful.</returns>
        private static bool MakeWindowMovable(Window window)
        {
            var source = GetWindowSource(window);
            if (source == null)
                return false;

            CaptionHitTester tester;
            if (!RegisteredWindows.TryGetValue(window, out tester))
            {
                // Register a CaptionHitTester for the window
                tester = new CaptionHitTester(window);
                RegisteredWindows[window] = tester;
                window.Closed += window_Closed; // Unregisters the window when it's closed
            }

            // Register the CaptionHitTester on the window (this is where the magic happens)
            tester.Hook(source);
            return true;
        }