Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }