Example #1
0
        private void TrackResizePreview(SplitterGrip grip, double horizontalChange, double verticalChange)
        {
            int gripIndex;
            int resizeIndex1;
            int resizeIndex2;

            if (!this.GetResizeIndices(grip, out gripIndex, out resizeIndex1, out resizeIndex2))
            {
                return;
            }
            double pixelAmount = this.Orientation == Orientation.Horizontal ? horizontalChange : verticalChange;
            IList <SplitterMeasureData> splitterMeasureDataList = SplitterMeasureData.FromElements((IList)this.InternalChildren);

            this.ResizeChildrenCore(splitterMeasureDataList[resizeIndex1], splitterMeasureDataList[resizeIndex2], pixelAmount);
            SplitterPanel.Measure(this.RenderSize, this.Orientation, (IEnumerable <SplitterMeasureData>)splitterMeasureDataList, false);
            Point point = grip.TransformToAncestor((Visual)this).Transform(new Point(0.0, 0.0));

            if (this.Orientation == Orientation.Horizontal)
            {
                point.X += splitterMeasureDataList[gripIndex].MeasuredBounds.Width - this.InternalChildren[gripIndex].RenderSize.Width;
            }
            else
            {
                point.Y += splitterMeasureDataList[gripIndex].MeasuredBounds.Height - this.InternalChildren[gripIndex].RenderSize.Height;
            }
            Point screen = this.PointToScreen(point);

            this.currentPreviewWindow.Move((double)(int)screen.X, (double)(int)screen.Y);
        }
Example #2
0
        private void CommitResize(SplitterGrip grip, double horizontalChange, double verticalChange)
        {
            int gripIndex;
            int resizeIndex1;
            int resizeIndex2;

            if (!this.GetResizeIndices(grip, out gripIndex, out resizeIndex1, out resizeIndex2))
            {
                return;
            }
            double pixelAmount = this.Orientation == Orientation.Horizontal ? horizontalChange : verticalChange;

            this.ResizeChildren(resizeIndex1, resizeIndex2, pixelAmount);
        }
Example #3
0
        private void OnSplitterResized(object sender, DragDeltaEventArgs args)
        {
            SplitterGrip grip = sender as SplitterGrip;

            if (grip == null)
            {
                return;
            }
            args.Handled = true;
            if (this.IsShowingResizePreview)
            {
                this.TrackResizePreview(grip, args.HorizontalChange, args.VerticalChange);
            }
            else
            {
                this.CommitResize(grip, args.HorizontalChange, args.VerticalChange);
            }
        }
Example #4
0
        private void OnSplitterDragStarted(object sender, DragStartedEventArgs args)
        {
            SplitterGrip originalSource = args.OriginalSource as SplitterGrip;

            if (originalSource == null)
            {
                return;
            }
            args.Handled                  = true;
            originalSource.DragDelta     += new DragDeltaEventHandler(this.OnSplitterResized);
            originalSource.DragCompleted += new DragCompletedEventHandler(this.OnSplitterDragCompleted);
            if (!this.ShowResizePreview)
            {
                return;
            }
            this.currentPreviewWindow = new SplitterResizePreviewWindow();
            this.currentPreviewWindow.Show((UIElement)originalSource);
        }
Example #5
0
        private bool GetResizeIndices(SplitterGrip grip, out int gripIndex, out int resizeIndex1, out int resizeIndex2)
        {
            for (int index = 0; index < this.InternalChildren.Count; ++index)
            {
                if (this.InternalChildren[index].IsAncestorOf((DependencyObject)grip))
                {
                    gripIndex = index;
                    switch (grip.ResizeBehavior)
                    {
                    case GridResizeBehavior.CurrentAndNext:
                        resizeIndex1 = index;
                        resizeIndex2 = index + 1;
                        break;

                    case GridResizeBehavior.PreviousAndCurrent:
                        resizeIndex1 = index - 1;
                        resizeIndex2 = index;
                        break;

                    case GridResizeBehavior.PreviousAndNext:
                        resizeIndex1 = index - 1;
                        resizeIndex2 = index + 1;
                        break;

                    default:
                        throw new InvalidOperationException("BasedOnAlignment is not a valid resize behavior");
                    }
                    if (resizeIndex1 >= 0 && resizeIndex2 >= 0 && resizeIndex1 < this.InternalChildren.Count)
                    {
                        return(resizeIndex2 < this.InternalChildren.Count);
                    }
                    return(false);
                }
            }
            gripIndex    = -1;
            resizeIndex1 = -1;
            resizeIndex2 = -1;
            return(false);
        }
Example #6
0
        private void OnSplitterDragCompleted(object sender, DragCompletedEventArgs args)
        {
            SplitterGrip grip = sender as SplitterGrip;

            if (grip == null)
            {
                return;
            }
            args.Handled = true;
            if (this.IsShowingResizePreview)
            {
                this.currentPreviewWindow.Hide();
                this.currentPreviewWindow = (SplitterResizePreviewWindow)null;
                if (!args.Canceled)
                {
                    Point logicalUnits = new Point(args.HorizontalChange, args.VerticalChange).DeviceToLogicalUnits();
                    this.CommitResize(grip, logicalUnits.X, logicalUnits.Y);
                }
            }
            grip.DragDelta     -= new DragDeltaEventHandler(this.OnSplitterResized);
            grip.DragCompleted -= new DragCompletedEventHandler(this.OnSplitterDragCompleted);
        }