Esempio n. 1
0
        /// <summary>
        /// Notifies that adorner element is being resizing either vertically or horizonally.
        /// Vertical and horizontal delta change is adjusted accordindly to minimum height and minimum width.
        /// Each corner computes it slighly differently, thus required delegates delegates.
        /// </summary>
        /// <param name="minWidth">Minimum width</param>
        /// <param name="oldWidth">Original width of the control</param>
        /// <param name="computedWidth">Width that has been computed with delta args, not necesarilly final widht, as it might have been set to minimum width</param>
        /// <param name="finalWidth">The final new width of the control.</param>
        /// <param name="minHeight">Minimum height.</param>
        /// <param name="oldHeight">Original height of the control</param>
        /// <param name="computedHeight">Height that has been computed with delta args, not necesarilly final height, as it might have been set to minimum height</param>
        /// <param name="finalHeight">The final new height of the control.</param>
        /// <param name="args">The <see cref="System.Windows.Controls.Primitives.DragDeltaEventArgs"/> instance containing the event data.</param>
        /// <param name="computeHorizontalChangeFunc">The function that must compute horizontal change adjusted to minimum</param>
        /// <param name="computeVerticalChangeFunc">The function that must compute vertical change adjusted to minimum</param>
        private void NotifyResizing(double minWidth, double oldWidth, double computedWidth, double finalWidth,
                                    double minHeight, double oldHeight, double computedHeight, double finalHeight,
                                    DragDeltaEventArgs args,
                                    CalculateHorizontalChange computeHorizontalChangeFunc,
                                    CalculateVerticalChange computeVerticalChangeFunc)
        {
            double verticalChange   = args.VerticalChange;
            double horizontalChange = args.HorizontalChange;

            if (finalWidth != oldWidth)
            {
                if (finalWidth == minWidth && computedWidth < minWidth)
                {
                    horizontalChange = computeHorizontalChangeFunc(minWidth, oldWidth);
                }

                NotifyResizingHorizontally(new DragDeltaEventArgs(horizontalChange, verticalChange));
            }

            if (finalHeight != oldHeight)
            {
                if (finalHeight == minHeight && computedHeight < minHeight)
                {
                    verticalChange = computeVerticalChangeFunc(minHeight, oldHeight);
                }

                NotifyResizingVertically(new DragDeltaEventArgs(horizontalChange, verticalChange));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handler for resizing from the bottom-right.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="System.Windows.Controls.Primitives.DragDeltaEventArgs"/> instance containing the event data.</param>
        private void HandleBottomRight(object sender, DragDeltaEventArgs args)
        {
            CalculateWidth  calculateWidthFunc  = (oldWidth) => { return(oldWidth + args.HorizontalChange); };
            CalculateHeight calculateHeightFunc = (oldHeight) => { return(oldHeight + args.VerticalChange); };

            CalculateHorizontalChange calculateHorizontalChangeFunc = (minWidth, oldWidth) => { return(minWidth - oldWidth); };
            CalculateVerticalChange   calculateVerticalChangeFunc   = (minHeight, oldHeight) => { return(minHeight - oldHeight); };

            // bottom right corner does not need to adjust the position of the element canvas
            SetAdornedElementCanvas setAdornedElementCanvas = (adornedElement, finalHeight, oldHeight, finalWidth, oldWidth) => { };

            HandleResizing(sender, args, calculateWidthFunc, calculateHeightFunc,
                           calculateHorizontalChangeFunc, calculateVerticalChangeFunc, setAdornedElementCanvas);
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the delta change of the thumb
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="System.Windows.Controls.Primitives.DragDeltaEventArgs"/> instance containing the event data.</param>
        /// <param name="computeWidthFunc">The function that must compute the new width.</param>
        /// <param name="computeHeightFunc">The function that must compute new height.</param>
        /// <param name="computeHorizontalChangeFunc">The function that must compute horizontal change adjusted to minimum</param>
        /// <param name="computeVerticalChangeFunc">The function that must compute vertical change adjusted to minimum</param>
        /// <param name="setAdornedElementCanvasFunc">The set adorned element canvas func.</param>
        private void HandleResizing(object sender, DragDeltaEventArgs args,
                                    CalculateWidth computeWidthFunc,
                                    CalculateHeight computeHeightFunc,
                                    CalculateHorizontalChange computeHorizontalChangeFunc,
                                    CalculateVerticalChange computeVerticalChangeFunc,
                                    SetAdornedElementCanvas setAdornedElementCanvasFunc)
        {
            FrameworkElement adornedElement = this.AdornedElement as FrameworkElement;
            Thumb            hitThumb       = sender as Thumb;

            if (adornedElement == null || hitThumb == null)
            {
                return;
            }

            double minWidth, oldWidth, computedWidth;
            double minHeight, oldHeight, computedHeight;

            // Ensure that the Width and Height are properly initialized after the resize.
            EnforceSize(adornedElement);

            minWidth  = adornedElement.MinWidth == 0 ? hitThumb.DesiredSize.Width : adornedElement.MinWidth;
            minHeight = adornedElement.MinHeight == 0 ? hitThumb.DesiredSize.Height : adornedElement.MinHeight;

            // Change the size by the amount the user drags the mouse, as long as it's larger
            // than the width or height of an adorner, respectively.
            oldWidth  = adornedElement.Width;
            oldHeight = adornedElement.Height;

            //compute width based on delta args
            computedWidth  = computeWidthFunc(oldWidth);
            computedHeight = computeHeightFunc(oldHeight);

            double finalWidth  = Math.Max(computedWidth, minWidth);
            double finalHeight = Math.Max(computedHeight, minHeight);

            adornedElement.Width  = finalWidth;
            adornedElement.Height = finalHeight;

            setAdornedElementCanvasFunc(adornedElement, finalHeight, oldHeight, finalWidth, oldWidth);

            double oldCanvasTop = Canvas.GetTop(adornedElement);

            Canvas.SetTop(adornedElement, oldCanvasTop - (finalHeight - oldHeight));

            NotifyResizing(minWidth, oldWidth, computedWidth, finalWidth,
                           minHeight, oldHeight, computedHeight, finalHeight,
                           args, computeHorizontalChangeFunc, computeVerticalChangeFunc);
        }
Esempio n. 4
0
        /// <summary>
        /// Handler for resizing from the bottom-left.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="System.Windows.Controls.Primitives.DragDeltaEventArgs"/> instance containing the event data.</param>
        private void HandleBottomLeft(object sender, DragDeltaEventArgs args)
        {
            CalculateWidth  calculateWidthFunc  = (oldWidth) => { return(oldWidth - args.HorizontalChange); };
            CalculateHeight calculateHeightFunc = (oldHeight) => { return(oldHeight + args.VerticalChange); };

            CalculateHorizontalChange calculateHorizontalChangeFunc = (minWidth, oldWidth) => { return(oldWidth - minWidth); };
            CalculateVerticalChange   calculateVerticalChangeFunc   = (minHeight, oldHeight) => { return(minHeight - oldHeight); };

            //bottom left corner needs to adjust position of left property of the element canvas
            SetAdornedElementCanvas setAdornedElementCanvas =
                (adornedElement, finalHeight, oldHeight, finalWidth, oldWidth) =>
            {
                double oldCanvasLeft = Canvas.GetLeft(adornedElement);
                Canvas.SetLeft(adornedElement, oldCanvasLeft - (finalWidth - oldWidth));
            };

            HandleResizing(sender, args, calculateWidthFunc, calculateHeightFunc,
                           calculateHorizontalChangeFunc, calculateVerticalChangeFunc, setAdornedElementCanvas);
        }
        /// <summary>
        /// Handles the delta change of the thumb
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="System.Windows.Controls.Primitives.DragDeltaEventArgs"/> instance containing the event data.</param>
        /// <param name="computeWidthFunc">The function that must compute the new width.</param>
        /// <param name="computeHeightFunc">The function that must compute new height.</param>
        /// <param name="computeHorizontalChangeFunc">The function that must compute horizontal change adjusted to minimum</param>
        /// <param name="computeVerticalChangeFunc">The function that must compute vertical change adjusted to minimum</param>
        /// <param name="setAdornedElementCanvasFunc">The set adorned element canvas func.</param>
        private void HandleResizing(object sender, DragDeltaEventArgs args,
                                 CalculateWidth computeWidthFunc,
                                 CalculateHeight computeHeightFunc,
                                 CalculateHorizontalChange computeHorizontalChangeFunc,
                                 CalculateVerticalChange computeVerticalChangeFunc,
                                 SetAdornedElementCanvas setAdornedElementCanvasFunc)
        {
            FrameworkElement adornedElement = this.AdornedElement as FrameworkElement;
            Thumb hitThumb = sender as Thumb;

            if (adornedElement == null || hitThumb == null) return;

            double minWidth, oldWidth, computedWidth;
            double minHeight, oldHeight, computedHeight;

            // Ensure that the Width and Height are properly initialized after the resize.
            EnforceSize(adornedElement);
            
            minWidth = adornedElement.MinWidth == 0 ? hitThumb.DesiredSize.Width : adornedElement.MinWidth;
            minHeight = adornedElement.MinHeight == 0 ? hitThumb.DesiredSize.Height : adornedElement.MinHeight;

            // Change the size by the amount the user drags the mouse, as long as it's larger 
            // than the width or height of an adorner, respectively.
            oldWidth = adornedElement.Width;
            oldHeight = adornedElement.Height;

            //compute width based on delta args
            computedWidth = computeWidthFunc(oldWidth);
            computedHeight = computeHeightFunc(oldHeight);

            double finalWidth = Math.Max(computedWidth, minWidth);
            double finalHeight = Math.Max(computedHeight, minHeight);

            adornedElement.Width = finalWidth;
            adornedElement.Height = finalHeight;
            
            setAdornedElementCanvasFunc(adornedElement, finalHeight, oldHeight, finalWidth, oldWidth);

            double oldCanvasTop = Canvas.GetTop(adornedElement);
            Canvas.SetTop(adornedElement, oldCanvasTop - (finalHeight - oldHeight));

            NotifyResizing(minWidth, oldWidth, computedWidth, finalWidth,
                           minHeight, oldHeight, computedHeight, finalHeight,
                           args, computeHorizontalChangeFunc, computeVerticalChangeFunc);
        }
        /// <summary>
        /// Notifies that adorner element is being resizing either vertically or horizonally.
        /// Vertical and horizontal delta change is adjusted accordindly to minimum height and minimum width.
        /// Each corner computes it slighly differently, thus required delegates delegates.
        /// </summary>
        /// <param name="minWidth">Minimum width</param>
        /// <param name="oldWidth">Original width of the control</param>
        /// <param name="computedWidth">Width that has been computed with delta args, not necesarilly final widht, as it might have been set to minimum width</param>
        /// <param name="finalWidth">The final new width of the control.</param>
        /// <param name="minHeight">Minimum height.</param>
        /// <param name="oldHeight">Original height of the control</param>
        /// <param name="computedHeight">Height that has been computed with delta args, not necesarilly final height, as it might have been set to minimum height</param>
        /// <param name="finalHeight">The final new height of the control.</param>
        /// <param name="args">The <see cref="System.Windows.Controls.Primitives.DragDeltaEventArgs"/> instance containing the event data.</param>
        /// <param name="computeHorizontalChangeFunc">The function that must compute horizontal change adjusted to minimum</param>
        /// <param name="computeVerticalChangeFunc">The function that must compute vertical change adjusted to minimum</param>
        private void NotifyResizing(double minWidth, double oldWidth, double computedWidth, double finalWidth, 
                                    double minHeight, double oldHeight, double computedHeight, double finalHeight, 
                                    DragDeltaEventArgs args, 
                                    CalculateHorizontalChange computeHorizontalChangeFunc,
                                    CalculateVerticalChange computeVerticalChangeFunc)
        {
            double verticalChange = args.VerticalChange;
            double horizontalChange = args.HorizontalChange;
            
            if (finalWidth != oldWidth)
            {
                if (finalWidth == minWidth && computedWidth < minWidth) 
                {
                    horizontalChange = computeHorizontalChangeFunc(minWidth, oldWidth); 
                }

                NotifyResizingHorizontally(new DragDeltaEventArgs(horizontalChange, verticalChange));
            }

            if (finalHeight != oldHeight)
            {
                if (finalHeight == minHeight && computedHeight < minHeight) 
                {
                    verticalChange = computeVerticalChangeFunc(minHeight, oldHeight);
                }

                NotifyResizingVertically(new DragDeltaEventArgs(horizontalChange, verticalChange));
            }
        }