Exemplo n.º 1
0
        private void GridSplitter_Loaded(object sender, RoutedEventArgs e)
        {
            _resizeDirection = GetResizeDirection();
            _resizeBehavior  = GetResizeBehavior();

            // Adding Grip to Grid Splitter
            if (Element == default(UIElement))
            {
                CreateGripperDisplay();
                Element = _gripperDisplay;
            }

            if (_hoverWrapper == null)
            {
                var hoverWrapper = new GripperHoverWrapper(
                    CursorBehavior == SplitterCursorBehavior.ChangeOnSplitterHover
                    ? this
                    : Element,
                    _resizeDirection,
                    GripperCursor,
                    GripperCustomCursorResource);
                ManipulationStarted   += hoverWrapper.SplitterManipulationStarted;
                ManipulationCompleted += hoverWrapper.SplitterManipulationCompleted;

                _hoverWrapper = hoverWrapper;
            }
        }
Exemplo n.º 2
0
        private static bool IsValidResizeBehavior(object o)
        {
            GridResizeBehavior resizeBehavior = (GridResizeBehavior)o;

            return(resizeBehavior == GridResizeBehavior.BasedOnAlignment ||
                   resizeBehavior == GridResizeBehavior.CurrentAndNext ||
                   resizeBehavior == GridResizeBehavior.PreviousAndCurrent ||
                   resizeBehavior == GridResizeBehavior.PreviousAndNext);
        }
Exemplo n.º 3
0
        private static void OnResizeBehaviorChanged(GridSplitter gridSplitter, GridResizeBehavior oldValue, GridResizeBehavior newValue)
        {
            ResettableGridSplitterBehavior behavior;

            if (behaviors.TryGetValue(gridSplitter, out behavior))
            {
                behavior.OnResizeBehaviorChanged(oldValue, newValue);
            }
        }
Exemplo n.º 4
0
        private static bool IsValidResizeBehavior(object o)
        {
            GridResizeBehavior behavior = (GridResizeBehavior)o;

            if (((behavior != GridResizeBehavior.BasedOnAlignment) && (behavior != GridResizeBehavior.CurrentAndNext)) && (behavior != GridResizeBehavior.PreviousAndCurrent))
            {
                return(behavior == GridResizeBehavior.PreviousAndNext);
            }
            return(true);
        }
Exemplo n.º 5
0
        // Determines the indices for accessign ColumnDefinitions or RowDefinitions based on resize direction and behavior
        private Tuple <int?, int?> GetDefinitionIndices()
        {
            GridResizeDirection effectiveResizeDirection = this.GetEffectiveResizeDirection();
            GridResizeBehavior  effectiveResizeBehavior  = this.GetEffectiveResizeBehavior(effectiveResizeDirection);

            int currentIndex;
            int count;

            switch (effectiveResizeDirection)
            {
            case GridResizeDirection.Columns:
                currentIndex = (int)this.gridSplitter.GetValue(Grid.ColumnProperty);
                count        = this.grid.ColumnDefinitions.Count;
                break;

            case GridResizeDirection.Rows:
                currentIndex = (int)this.gridSplitter.GetValue(Grid.RowProperty);
                count        = this.grid.RowDefinitions.Count;
                break;

            default:
                return(new Tuple <int?, int?>(null, null));
            }

            int?length1Index = currentIndex;
            int?length2Index = currentIndex;

            switch (effectiveResizeBehavior)
            {
            case GridResizeBehavior.CurrentAndNext:
                length2Index++;
                break;

            case GridResizeBehavior.PreviousAndCurrent:
                length1Index--;
                break;

            case GridResizeBehavior.PreviousAndNext:
                length2Index++;
                length1Index--;
                break;
            }

            if (length1Index < 0 || length1Index >= count)
            {
                length1Index = null;
            }

            if (length2Index < 0 || length2Index >= count)
            {
                length2Index = null;
            }

            return(new Tuple <int?, int?>(length1Index, length2Index));
        }
Exemplo n.º 6
0
        // Token: 0x06004DCE RID: 19918 RVA: 0x0015EE20 File Offset: 0x0015D020
        private bool SetupDefinitionsToResize()
        {
            int num = (int)base.GetValue((this._resizeData.ResizeDirection == GridResizeDirection.Columns) ? Grid.ColumnSpanProperty : Grid.RowSpanProperty);

            if (num == 1)
            {
                int num2 = (int)base.GetValue((this._resizeData.ResizeDirection == GridResizeDirection.Columns) ? Grid.ColumnProperty : Grid.RowProperty);
                GridResizeBehavior resizeBehavior = this._resizeData.ResizeBehavior;
                int num3;
                int num4;
                if (resizeBehavior != GridResizeBehavior.CurrentAndNext)
                {
                    if (resizeBehavior == GridResizeBehavior.PreviousAndCurrent)
                    {
                        num3 = num2 - 1;
                        num4 = num2;
                    }
                    else
                    {
                        num3 = num2 - 1;
                        num4 = num2 + 1;
                    }
                }
                else
                {
                    num3 = num2;
                    num4 = num2 + 1;
                }
                int num5 = (this._resizeData.ResizeDirection == GridResizeDirection.Columns) ? this._resizeData.Grid.ColumnDefinitions.Count : this._resizeData.Grid.RowDefinitions.Count;
                if (num3 >= 0 && num4 < num5)
                {
                    this._resizeData.SplitterIndex                   = num2;
                    this._resizeData.Definition1Index                = num3;
                    this._resizeData.Definition1                     = GridSplitter.GetGridDefinition(this._resizeData.Grid, num3, this._resizeData.ResizeDirection);
                    this._resizeData.OriginalDefinition1Length       = this._resizeData.Definition1.UserSizeValueCache;
                    this._resizeData.OriginalDefinition1ActualLength = this.GetActualLength(this._resizeData.Definition1);
                    this._resizeData.Definition2Index                = num4;
                    this._resizeData.Definition2                     = GridSplitter.GetGridDefinition(this._resizeData.Grid, num4, this._resizeData.ResizeDirection);
                    this._resizeData.OriginalDefinition2Length       = this._resizeData.Definition2.UserSizeValueCache;
                    this._resizeData.OriginalDefinition2ActualLength = this.GetActualLength(this._resizeData.Definition2);
                    bool flag  = GridSplitter.IsStar(this._resizeData.Definition1);
                    bool flag2 = GridSplitter.IsStar(this._resizeData.Definition2);
                    if (flag && flag2)
                    {
                        this._resizeData.SplitBehavior = GridSplitter.SplitBehavior.Split;
                    }
                    else
                    {
                        this._resizeData.SplitBehavior = ((!flag) ? GridSplitter.SplitBehavior.Resize1 : GridSplitter.SplitBehavior.Resize2);
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 7
0
        // Token: 0x06004DCA RID: 19914 RVA: 0x0015ECD0 File Offset: 0x0015CED0
        private GridResizeBehavior GetEffectiveResizeBehavior(GridResizeDirection direction)
        {
            GridResizeBehavior gridResizeBehavior = this.ResizeBehavior;

            if (gridResizeBehavior == GridResizeBehavior.BasedOnAlignment)
            {
                if (direction == GridResizeDirection.Columns)
                {
                    HorizontalAlignment horizontalAlignment = base.HorizontalAlignment;
                    if (horizontalAlignment != HorizontalAlignment.Left)
                    {
                        if (horizontalAlignment != HorizontalAlignment.Right)
                        {
                            gridResizeBehavior = GridResizeBehavior.PreviousAndNext;
                        }
                        else
                        {
                            gridResizeBehavior = GridResizeBehavior.CurrentAndNext;
                        }
                    }
                    else
                    {
                        gridResizeBehavior = GridResizeBehavior.PreviousAndCurrent;
                    }
                }
                else
                {
                    VerticalAlignment verticalAlignment = base.VerticalAlignment;
                    if (verticalAlignment != VerticalAlignment.Top)
                    {
                        if (verticalAlignment != VerticalAlignment.Bottom)
                        {
                            gridResizeBehavior = GridResizeBehavior.PreviousAndNext;
                        }
                        else
                        {
                            gridResizeBehavior = GridResizeBehavior.CurrentAndNext;
                        }
                    }
                    else
                    {
                        gridResizeBehavior = GridResizeBehavior.PreviousAndCurrent;
                    }
                }
            }
            return(gridResizeBehavior);
        }
Exemplo n.º 8
0
        // Get the resize behavior (Which columns/rows should be resized) based on alignment and Direction
        private GridResizeBehavior GetResizeBehavior()
        {
            GridResizeBehavior resizeBehavior = ResizeBehavior;

            if (resizeBehavior == GridResizeBehavior.BasedOnAlignment)
            {
                if (_resizeDirection == GridResizeDirection.Columns)
                {
                    switch (HorizontalAlignment)
                    {
                    case HorizontalAlignment.Left:
                        resizeBehavior = GridResizeBehavior.PreviousAndCurrent;
                        break;

                    case HorizontalAlignment.Right:
                        resizeBehavior = GridResizeBehavior.CurrentAndNext;
                        break;

                    default:
                        resizeBehavior = GridResizeBehavior.PreviousAndNext;
                        break;
                    }
                }

                // resize direction is vertical
                else
                {
                    switch (VerticalAlignment)
                    {
                    case VerticalAlignment.Top:
                        resizeBehavior = GridResizeBehavior.PreviousAndCurrent;
                        break;

                    case VerticalAlignment.Bottom:
                        resizeBehavior = GridResizeBehavior.CurrentAndNext;
                        break;

                    default:
                        resizeBehavior = GridResizeBehavior.PreviousAndNext;
                        break;
                    }
                }
            }

            return(resizeBehavior);
        }
Exemplo n.º 9
0
        /// <inheritdoc />
        protected override void OnManipulationStarted(ManipulationStartedRoutedEventArgs e)
        {
            // saving the previous state
            PreviousCursor   = Window.Current.CoreWindow.PointerCursor;
            _resizeDirection = GetResizeDirection();
            _resizeBehavior  = GetResizeBehavior();

            if (_resizeDirection == GridResizeDirection.Columns)
            {
                Window.Current.CoreWindow.PointerCursor = ColumnsSplitterCursor;
            }
            else if (_resizeDirection == GridResizeDirection.Rows)
            {
                Window.Current.CoreWindow.PointerCursor = RowSplitterCursor;
            }

            base.OnManipulationStarted(e);
        }
Exemplo n.º 10
0
        GridResizeBehavior GetActualResizeBehavior(GridResizeDirection resizeDirection)
        {
            GridResizeBehavior value = ResizeBehavior;

            if (value == GridResizeBehavior.BasedOnAlignment)
            {
                if (resizeDirection == GridResizeDirection.Rows)
                {
                    switch (VerticalAlignment)
                    {
                    case VerticalAlignment.Top:
                        return(GridResizeBehavior.PreviousAndCurrent);

                    case VerticalAlignment.Bottom:
                        return(GridResizeBehavior.CurrentAndNext);

                    default:
                        return(GridResizeBehavior.PreviousAndNext);
                    }
                }
                else
                {
                    switch (HorizontalAlignment)
                    {
                    case HorizontalAlignment.Left:
                        return(GridResizeBehavior.PreviousAndCurrent);

                    case HorizontalAlignment.Right:
                        return(GridResizeBehavior.CurrentAndNext);

                    default:
                        return(GridResizeBehavior.PreviousAndNext);
                    }
                }
            }
            else
            {
                return(value);
            }
        }
Exemplo n.º 11
0
        private GridResizeBehavior GetEffectiveResizeBehavior(GridResizeDirection direction)
        {
            GridResizeBehavior resizeBehavior = this.ResizeBehavior;

            if (resizeBehavior != GridResizeBehavior.BasedOnAlignment)
            {
                return(resizeBehavior);
            }
            if (direction != GridResizeDirection.Columns)
            {
                switch (base.VerticalAlignment)
                {
                case VerticalAlignment.Top:
                    return(GridResizeBehavior.PreviousAndCurrent);

                case VerticalAlignment.Center:
                    goto Label_0058;

                case VerticalAlignment.Bottom:
                    return(GridResizeBehavior.CurrentAndNext);
                }
            }
            else
            {
                switch (base.HorizontalAlignment)
                {
                case HorizontalAlignment.Left:
                    return(GridResizeBehavior.PreviousAndCurrent);

                case HorizontalAlignment.Right:
                    return(GridResizeBehavior.CurrentAndNext);
                }
                return(GridResizeBehavior.PreviousAndNext);
            }
Label_0058:
            return(GridResizeBehavior.PreviousAndNext);
        }
Exemplo n.º 12
0
        private void ResizeRows(Grid grid, double deltaX)
        {
            GridResizeBehavior effectiveGridResizeBehavior =
                this.DetermineEffectiveResizeBehavior();

            int row = Grid.GetRow(this);
            int upperRow;
            int lowerRow;

            switch (effectiveGridResizeBehavior)
            {
            case GridResizeBehavior.PreviousAndCurrent:
                upperRow = row - 1;
                lowerRow = row;
                break;

            case GridResizeBehavior.PreviousAndNext:
                upperRow = row - 1;
                lowerRow = row + 1;
                break;

            default:
                upperRow = row;
                lowerRow = row + 1;
                break;
            }

            if (lowerRow >= grid.RowDefinitions.Count)
            {
                return;
            }

            var upperRowDefinition   = grid.RowDefinitions[upperRow];
            var lowerRowDefinition   = grid.RowDefinitions[lowerRow];
            var upperRowGridUnitType = upperRowDefinition.Height.GridUnitType;
            var lowerRowGridUnitType = lowerRowDefinition.Height.GridUnitType;
            var upperRowActualHeight = upperRowDefinition.ActualHeight;
            var lowerRowActualHeight = lowerRowDefinition.ActualHeight;
            var upperRowMaxHeight    = upperRowDefinition.MaxHeight;
            var lowerRowMaxHeight    = lowerRowDefinition.MaxHeight;
            var upperRowMinHeight    = upperRowDefinition.MinHeight;
            var lowerRowMinHeight    = lowerRowDefinition.MinHeight;

            //deltaX = 200;
            if (upperRowActualHeight + deltaX > upperRowMaxHeight)
            {
                deltaX = Math.Max(
                    0,
                    upperRowDefinition.MaxHeight - upperRowActualHeight);
            }

            if (upperRowActualHeight + deltaX < upperRowMinHeight)
            {
                deltaX = Math.Min(
                    0,
                    upperRowDefinition.MinHeight - upperRowActualHeight);
            }

            if (lowerRowActualHeight - deltaX > lowerRowMaxHeight)
            {
                deltaX = -Math.Max(
                    0,
                    lowerRowDefinition.MaxHeight - lowerRowActualHeight);
            }

            if (lowerRowActualHeight - deltaX < lowerRowMinHeight)
            {
                deltaX = -Math.Min(
                    0,
                    lowerRowDefinition.MinHeight - lowerRowActualHeight);
            }

            var newUpperRowActualHeight = upperRowActualHeight + deltaX;
            var newLowerRowActualHeight = lowerRowActualHeight - deltaX;

            grid.BeginInit();

            double totalStarRowsHeight     = 0;
            double starRowsAvailableHeight = grid.ActualHeight;

            if (upperRowGridUnitType ==
                GridUnitType.Star ||
                lowerRowGridUnitType ==
                GridUnitType.Star)
            {
                foreach (var rowDefinition in grid.RowDefinitions)
                {
                    if (rowDefinition.Height.GridUnitType ==
                        GridUnitType.Star)
                    {
                        totalStarRowsHeight +=
                            rowDefinition.Height.Value;
                    }
                    else
                    {
                        starRowsAvailableHeight -=
                            rowDefinition.ActualHeight;
                    }
                }
            }

            if (upperRowGridUnitType == GridUnitType.Star)
            {
                if (lowerRowGridUnitType == GridUnitType.Star)
                {
                    // If both rows are star rows
                    // - totalStarRowsHeight won't change and
                    // as much as one of the rows grows
                    // - the other row will shrink by the same value.

                    // If there is no width available to star rows
                    // - we can't resize two of them.
                    if (starRowsAvailableHeight < 1)
                    {
                        return;
                    }

                    var oldStarHeight = upperRowDefinition.Height.Value;
                    var newStarHeight = Math.Max(
                        0,
                        totalStarRowsHeight * newUpperRowActualHeight /
                        starRowsAvailableHeight);
                    upperRowDefinition.Height =
                        new GridLength(newStarHeight, GridUnitType.Star);

                    lowerRowDefinition.Height =
                        new GridLength(
                            Math.Max(
                                0,
                                lowerRowDefinition.Height.Value -
                                newStarHeight + oldStarHeight),
                            GridUnitType.Star);
                }
                else
                {
                    var newStarRowsAvailableHeight =
                        starRowsAvailableHeight +
                        lowerRowActualHeight -
                        newLowerRowActualHeight;

                    if (newStarRowsAvailableHeight - newUpperRowActualHeight >= 1)
                    {
                        var newStarHeight = Math.Max(
                            0,
                            (totalStarRowsHeight -
                             upperRowDefinition.Height.Value) *
                            newUpperRowActualHeight /
                            (newStarRowsAvailableHeight - newUpperRowActualHeight));

                        upperRowDefinition.Height =
                            new GridLength(newStarHeight, GridUnitType.Star);
                    }
                }
            }
            else
            {
                upperRowDefinition.Height =
                    new GridLength(
                        newUpperRowActualHeight, GridUnitType.Pixel);
            }

            if (lowerRowGridUnitType ==
                GridUnitType.Star)
            {
                if (upperRowGridUnitType !=
                    GridUnitType.Star)
                {
                    var newStarRowsAvailableHeight =
                        starRowsAvailableHeight +
                        upperRowActualHeight -
                        newUpperRowActualHeight;

                    if (newStarRowsAvailableHeight - newLowerRowActualHeight >= 1)
                    {
                        var newStarHeight = Math.Max(
                            0,
                            (totalStarRowsHeight -
                             lowerRowDefinition.Height.Value) *
                            newLowerRowActualHeight /
                            (newStarRowsAvailableHeight - newLowerRowActualHeight));
                        lowerRowDefinition.Height =
                            new GridLength(newStarHeight, GridUnitType.Star);
                    }
                }
                // else handled in the upper row width calculation block
            }
            else
            {
                lowerRowDefinition.Height =
                    new GridLength(
                        newLowerRowActualHeight, GridUnitType.Pixel);
            }

            grid.EndInit();
        }
Exemplo n.º 13
0
        private void ResizeColumns(Grid grid, double deltaX)
        {
            GridResizeBehavior effectiveGridResizeBehavior =
                this.DetermineEffectiveResizeBehavior();

            int column = Grid.GetColumn(this);
            int leftColumn;
            int rightColumn;

            switch (effectiveGridResizeBehavior)
            {
            case GridResizeBehavior.PreviousAndCurrent:
                leftColumn  = column - 1;
                rightColumn = column;
                break;

            case GridResizeBehavior.PreviousAndNext:
                leftColumn  = column - 1;
                rightColumn = column + 1;
                break;

            default:
                leftColumn  = column;
                rightColumn = column + 1;
                break;
            }

            if (rightColumn >= grid.ColumnDefinitions.Count)
            {
                return;
            }

            var leftColumnDefinition    = grid.ColumnDefinitions[leftColumn];
            var rightColumnDefinition   = grid.ColumnDefinitions[rightColumn];
            var leftColumnGridUnitType  = leftColumnDefinition.Width.GridUnitType;
            var rightColumnGridUnitType = rightColumnDefinition.Width.GridUnitType;
            var leftColumnActualWidth   = leftColumnDefinition.ActualWidth;
            var rightColumnActualWidth  = rightColumnDefinition.ActualWidth;
            var leftColumnMaxWidth      = leftColumnDefinition.MaxWidth;
            var rightColumnMaxWidth     = rightColumnDefinition.MaxWidth;
            var leftColumnMinWidth      = leftColumnDefinition.MinWidth;
            var rightColumnMinWidth     = rightColumnDefinition.MinWidth;

            //deltaX = 200;
            if (leftColumnActualWidth + deltaX > leftColumnMaxWidth)
            {
                deltaX = Math.Max(
                    0,
                    leftColumnDefinition.MaxWidth - leftColumnActualWidth);
            }

            if (leftColumnActualWidth + deltaX < leftColumnMinWidth)
            {
                deltaX = Math.Min(
                    0,
                    leftColumnDefinition.MinWidth - leftColumnActualWidth);
            }

            if (rightColumnActualWidth - deltaX > rightColumnMaxWidth)
            {
                deltaX = -Math.Max(
                    0,
                    rightColumnDefinition.MaxWidth - rightColumnActualWidth);
            }

            if (rightColumnActualWidth - deltaX < rightColumnMinWidth)
            {
                deltaX = -Math.Min(
                    0,
                    rightColumnDefinition.MinWidth - rightColumnActualWidth);
            }

            var newLeftColumnActualWidth  = leftColumnActualWidth + deltaX;
            var newRightColumnActualWidth = rightColumnActualWidth - deltaX;

            grid.BeginInit();

            double totalStarColumnsWidth     = 0;
            double starColumnsAvailableWidth = grid.ActualWidth;

            if (leftColumnGridUnitType ==
                GridUnitType.Star ||
                rightColumnGridUnitType ==
                GridUnitType.Star)
            {
                foreach (var columnDefinition in grid.ColumnDefinitions)
                {
                    if (columnDefinition.Width.GridUnitType ==
                        GridUnitType.Star)
                    {
                        totalStarColumnsWidth +=
                            columnDefinition.Width.Value;
                    }
                    else
                    {
                        starColumnsAvailableWidth -=
                            columnDefinition.ActualWidth;
                    }
                }
            }

            if (leftColumnGridUnitType == GridUnitType.Star)
            {
                if (rightColumnGridUnitType == GridUnitType.Star)
                {
                    // If both columns are star columns
                    // - totalStarColumnsWidth won't change and
                    // as much as one of the columns grows
                    // - the other column will shrink by the same value.

                    // If there is no width available to star columns
                    // - we can't resize two of them.
                    if (starColumnsAvailableWidth < 1)
                    {
                        return;
                    }

                    var oldStarWidth = leftColumnDefinition.Width.Value;
                    var newStarWidth = Math.Max(
                        0,
                        totalStarColumnsWidth * newLeftColumnActualWidth /
                        starColumnsAvailableWidth);
                    leftColumnDefinition.Width =
                        new GridLength(newStarWidth, GridUnitType.Star);

                    rightColumnDefinition.Width =
                        new GridLength(
                            Math.Max(
                                0,
                                rightColumnDefinition.Width.Value -
                                newStarWidth + oldStarWidth),
                            GridUnitType.Star);
                }
                else
                {
                    var newStarColumnsAvailableWidth =
                        starColumnsAvailableWidth +
                        rightColumnActualWidth -
                        newRightColumnActualWidth;

                    if (newStarColumnsAvailableWidth - newLeftColumnActualWidth >= 1)
                    {
                        var newStarWidth = Math.Max(
                            0,
                            (totalStarColumnsWidth -
                             leftColumnDefinition.Width.Value) *
                            newLeftColumnActualWidth /
                            (newStarColumnsAvailableWidth - newLeftColumnActualWidth));

                        leftColumnDefinition.Width =
                            new GridLength(newStarWidth, GridUnitType.Star);
                    }
                }
            }
            else
            {
                leftColumnDefinition.Width =
                    new GridLength(
                        newLeftColumnActualWidth, GridUnitType.Pixel);
            }

            if (rightColumnGridUnitType ==
                GridUnitType.Star)
            {
                if (leftColumnGridUnitType !=
                    GridUnitType.Star)
                {
                    var newStarColumnsAvailableWidth =
                        starColumnsAvailableWidth +
                        leftColumnActualWidth -
                        newLeftColumnActualWidth;

                    if (newStarColumnsAvailableWidth - newRightColumnActualWidth >= 1)
                    {
                        var newStarWidth = Math.Max(
                            0,
                            (totalStarColumnsWidth -
                             rightColumnDefinition.Width.Value) *
                            newRightColumnActualWidth /
                            (newStarColumnsAvailableWidth - newRightColumnActualWidth));
                        rightColumnDefinition.Width =
                            new GridLength(newStarWidth, GridUnitType.Star);
                    }
                }
                // else handled in the left column width calculation block
            }
            else
            {
                rightColumnDefinition.Width =
                    new GridLength(
                        newRightColumnActualWidth, GridUnitType.Pixel);
            }

            grid.EndInit();
        }
 public static T ResizeBehavior <T>(this T target, GridResizeBehavior value) where T : GridSplitter
 {
     target.ResizeBehavior = value;
     return(target);
 }
Exemplo n.º 15
0
 private void OnResizeBehaviorChanged(GridResizeBehavior oldValue, GridResizeBehavior newValue)
 {
     this.SnapshotSplitterPosition();
 }
Exemplo n.º 16
0
        void HandleChange(Grid grid, GridResizeDirection resizeDirection, double change)
        {
            GridResizeBehavior resize_behavior = GetActualResizeBehavior(resizeDirection);
            int    position_in_grid;
            int    definition_index1;
            int    definition_index2;
            double definition1_actual_size;
            double definition2_actual_size;
            double minimum_size1;
            double minimum_size2;

            if (resizeDirection == GridResizeDirection.Rows)
            {
                position_in_grid = Grid.GetRow(this);
                switch (resize_behavior)
                {
                case GridResizeBehavior.CurrentAndNext:
                    definition_index1 = position_in_grid;
                    definition_index2 = position_in_grid + 1;
                    break;

                case GridResizeBehavior.PreviousAndCurrent:
                    definition_index1 = position_in_grid - 1;
                    definition_index2 = position_in_grid;
                    break;

                default:
                    definition_index1 = position_in_grid - 1;
                    definition_index2 = position_in_grid + 1;
                    break;
                }
                if (CheckDefinitionIndex(grid.RowDefinitions, definition_index1))
                {
                    return;
                }
                if (CheckDefinitionIndex(grid.RowDefinitions, definition_index2))
                {
                    return;
                }
                RowDefinition definition1 = grid.RowDefinitions [definition_index1];
                RowDefinition definition2 = grid.RowDefinitions [definition_index2];
                switch (resize_behavior)
                {
                case GridResizeBehavior.PreviousAndNext:
                    minimum_size1 = 0;
                    minimum_size2 = 0;
                    break;

                default:
                    switch (VerticalAlignment)
                    {
                    case VerticalAlignment.Top:
                        minimum_size1 = 0;
                        minimum_size2 = ActualHeight;
                        break;

                    case VerticalAlignment.Bottom:
                        minimum_size1 = ActualHeight;
                        minimum_size2 = 0;
                        break;

                    default:
                        minimum_size1 = ActualHeight;
                        minimum_size2 = 0;
                        break;
                    }
                    break;
                }
                definition1_actual_size = definition1.ActualHeight;
                if (definition1_actual_size + change < minimum_size1)
                {
                    change = minimum_size1 - definition1_actual_size;
                }
                definition2_actual_size = definition2.ActualHeight;
                if (definition2_actual_size - change < minimum_size2)
                {
                    change = definition2_actual_size - minimum_size2;
                }
                definition1.Height = new GridLength(definition1_actual_size + change);
                definition2.Height = new GridLength(definition2_actual_size - change);
            }
            else
            {
                position_in_grid = Grid.GetColumn(this);
                switch (resize_behavior)
                {
                case GridResizeBehavior.CurrentAndNext:
                    definition_index1 = position_in_grid;
                    definition_index2 = position_in_grid + 1;
                    break;

                case GridResizeBehavior.PreviousAndCurrent:
                    definition_index1 = position_in_grid - 1;
                    definition_index2 = position_in_grid;
                    break;

                default:
                    definition_index1 = position_in_grid - 1;
                    definition_index2 = position_in_grid + 1;
                    break;
                }
                if (CheckDefinitionIndex(grid.RowDefinitions, definition_index1))
                {
                    return;
                }
                if (CheckDefinitionIndex(grid.RowDefinitions, definition_index2))
                {
                    return;
                }
                ColumnDefinition definition1 = grid.ColumnDefinitions [definition_index1];
                ColumnDefinition definition2 = grid.ColumnDefinitions [definition_index2];
                switch (resize_behavior)
                {
                case GridResizeBehavior.PreviousAndNext:
                    minimum_size1 = 0;
                    minimum_size2 = 0;
                    break;

                default:
                    switch (HorizontalAlignment)
                    {
                    case HorizontalAlignment.Left:
                        minimum_size1 = 0;
                        minimum_size2 = ActualWidth;
                        break;

                    case HorizontalAlignment.Right:
                        minimum_size1 = ActualWidth;
                        minimum_size2 = 0;
                        break;

                    default:
                        minimum_size1 = ActualWidth;
                        minimum_size2 = 0;
                        break;
                    }
                    break;
                }
                definition1_actual_size = definition1.ActualWidth;
                if (definition1_actual_size + change < minimum_size1)
                {
                    change = minimum_size1 - definition1_actual_size;
                }
                definition2_actual_size = definition2.ActualWidth;
                if (definition2_actual_size - change < minimum_size2)
                {
                    change = definition2_actual_size - minimum_size2;
                }
                definition1.Width = new GridLength(definition1_actual_size + change);
                definition2.Width = new GridLength(definition2_actual_size - change);
            }
        }