예제 #1
0
        private void RegisterBorderEvents(WindowBorderEdge borderEdge, FrameworkElement border)
        {
            //START HERE WITH CODE ON LAST PIC Time 24.34 of 49.41 Custom Window Chrome
            //youtube DCOM engineering LLC
            //MouseEnter validated 2/22
            border.MouseEnter += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize)
                {
                    switch (borderEdge)
                    {
                    case WindowBorderEdge.Left:
                    case WindowBorderEdge.Right:
                        border.Cursor = Cursors.SizeWE;
                        break;

                    case WindowBorderEdge.Top:
                    case WindowBorderEdge.Bottom:
                        border.Cursor = Cursors.SizeNS;
                        break;

                    case WindowBorderEdge.TopLeft:
                    case WindowBorderEdge.BottomRight:
                        border.Cursor = Cursors.SizeNWSE;
                        break;

                    case WindowBorderEdge.TopRight:
                    case WindowBorderEdge.BottomLeft:
                        border.Cursor = Cursors.SizeNESW;
                        break;
                    }
                }
                else
                {
                    border.Cursor = Cursors.Arrow;
                }
            };
            //Valididated 2/22 had capitalX and Y's
            border.MouseLeftButtonDown += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize)
                {
                    System.Windows.Point cursorLocation = e.GetPosition(this);
                    System.Windows.Point cursorOffset   = new System.Windows.Point();

                    switch (borderEdge)
                    {
                    case WindowBorderEdge.Left:
                        cursorOffset.X = cursorLocation.X;
                        break;

                    case WindowBorderEdge.TopLeft:
                        cursorOffset.X = cursorLocation.X;
                        cursorOffset.Y = cursorLocation.Y;
                        break;

                    case WindowBorderEdge.Top:
                        cursorOffset.Y = cursorLocation.Y;
                        break;

                    case WindowBorderEdge.TopRight:
                        cursorOffset.X = (Width - cursorLocation.X);
                        cursorOffset.Y = cursorLocation.Y;
                        break;

                    case WindowBorderEdge.Right:
                        cursorOffset.X = (Width - cursorLocation.X);
                        break;

                    case WindowBorderEdge.BottomRight:
                        cursorOffset.X = (Width - cursorLocation.X);
                        cursorOffset.Y = (Height - cursorLocation.Y);
                        break;

                    case WindowBorderEdge.Bottom:
                        cursorOffset.Y = (Height - cursorLocation.Y);
                        break;

                    case WindowBorderEdge.BottomLeft:
                        cursorOffset.X = cursorLocation.X;
                        cursorOffset.Y = (Height - cursorLocation.Y);
                        break;
                    }
                    this.cursorOffset = cursorOffset;

                    border.CaptureMouse();
                }
            };

            border.MouseMove += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && border.IsMouseCaptured && ResizeMode == ResizeMode.CanResize)
                {
                    System.Windows.Point cursorLocation = e.GetPosition(this);

                    double nHorizontalChange = (cursorLocation.X - cursorOffset.X);
                    double pHorizontalChange = (cursorLocation.X + cursorOffset.X);
                    double nVerticalChange   = (cursorLocation.Y - cursorOffset.Y);
                    double pVerticalChange   = (cursorLocation.Y + cursorOffset.Y);

                    switch (borderEdge)
                    {
                    case WindowBorderEdge.Left:
                        if (Width - nHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Left  += nHorizontalChange;
                        Width -= nHorizontalChange;
                        break;

                    case WindowBorderEdge.TopLeft:
                        if (Width - nHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Left  += nHorizontalChange;
                        Width -= nHorizontalChange;
                        if (Height - nVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Top    += nVerticalChange;
                        Height -= nVerticalChange;
                        break;

                    case WindowBorderEdge.Top:
                        if (Height - nVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Top    += nVerticalChange;
                        Height -= nVerticalChange;
                        break;

                    case WindowBorderEdge.TopRight:
                        if (pHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Width = pHorizontalChange;
                        if (Height - nVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Top    += nVerticalChange;
                        Height -= nVerticalChange;
                        break;

                    case WindowBorderEdge.Right:
                        if (pHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Width = pHorizontalChange;
                        break;

                    case WindowBorderEdge.BottomRight:
                        if (pHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Width = pHorizontalChange;
                        if (pVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Height = pVerticalChange;
                        break;

                    case WindowBorderEdge.Bottom:
                        if (pVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Height = pVerticalChange;
                        break;

                    case WindowBorderEdge.BottomLeft:
                        if (Width - nHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Left += nHorizontalChange;
                        Width = nHorizontalChange;
                        if (pVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Height = pVerticalChange;
                        break;
                    }
                }
            };
            border.MouseLeftButtonUp += (sender, e) =>
            {
                border.ReleaseMouseCapture();
            };
        }
예제 #2
0
파일: ThemedWindow.cs 프로젝트: Techide/DMC
        private void RegisterBorderEvents(WindowBorderEdge borderEdge, IInputElement border)
        {
            #region MouseEnter
            border.MouseEnter += (sender, e) =>
                {
                    if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize)
                    {
                        _normalBorderStyle = (Brush)TryFindResource("BorderBrush");
                        _highlightBorderBrush = (Brush)TryFindResource("BorderHighlightBrush");

                        switch (borderEdge)
                        {
                            case WindowBorderEdge.Left:
                                using (var cursor = new OverrideCursor(Cursors.SizeWE))
                                {
                                    _borderLeft.Background = _highlightBorderBrush;
                                }
                                    _borderLeft.Background = _highlightBorderBrush;
                                break;
                            case WindowBorderEdge.Right:
                                using (var cursor = new OverrideCursor(Cursors.SizeWE))
                                {

                                }
                            //Cursor = Cursors.SizeWE;
                                break;
                            case WindowBorderEdge.Top:
                            case WindowBorderEdge.Bottom:
                                using (var cursor = new OverrideCursor(Cursors.SizeNS))
                                {

                                }
                                //Cursor = Cursors.SizeNS;
                                break;
                            case WindowBorderEdge.TopLeft:
                            case WindowBorderEdge.BottomRight:
                                using (var cursor = new OverrideCursor(Cursors.SizeNWSE))
                                {

                                }
                                //Cursor = Cursors.SizeNWSE;
                                break;
                            case WindowBorderEdge.TopRight:
                            case WindowBorderEdge.BottomLeft:
                                using (var cursor = new OverrideCursor(Cursors.SizeNESW))
                                {

                                }
                                //Cursor = Cursors.SizeNESW;
                                break;
                        }
                    }
                    //else
                    //{
                    //    Cursor = Cursors.Arrow;
                    //}
                };
            #endregion

            #region MouseLeave
            //border.MouseLeave += (sender, e) => Cursor = Cursors.Arrow;
            #endregion

            #region MouseLeftButtonDown
            border.MouseLeftButtonDown += (sender, e) =>
                {
                    if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize)
                    {
                        var cursorLocation = e.GetPosition(this);
                        var cursorOffset = new Point();

                        switch (borderEdge)
                        {
                            case WindowBorderEdge.Left:
                                cursorOffset.X = cursorLocation.X;
                                break;
                            case WindowBorderEdge.TopLeft:
                                cursorOffset.X = cursorLocation.X;
                                cursorOffset.Y = cursorLocation.Y;
                                break;
                            case WindowBorderEdge.Top:
                                cursorOffset.Y = cursorLocation.Y;
                                break;
                            case WindowBorderEdge.TopRight:
                                cursorOffset.X = (Width - cursorLocation.X);
                                cursorOffset.Y = cursorLocation.Y;
                                break;
                            case WindowBorderEdge.Right:
                                cursorOffset.X = (Width - cursorLocation.X);
                                break;
                            case WindowBorderEdge.BottomRight:
                                cursorOffset.X = (Width - cursorLocation.X);
                                cursorOffset.Y = (Height - cursorLocation.Y);
                                break;
                            case WindowBorderEdge.Bottom:
                                cursorOffset.Y = (Height - cursorLocation.Y);
                                break;
                            case WindowBorderEdge.BottomLeft:
                                cursorOffset.X = cursorLocation.X;
                                cursorOffset.Y = (Height - cursorLocation.Y);
                                break;
                        }

                        _cursorOffset = cursorOffset;

                        border.CaptureMouse();
                    }
                };
            #endregion

            #region MouseMove
            //border.PreviewMouseMove

            border.MouseMove += (sender, e) =>
                {
                    if (WindowState != WindowState.Maximized && border.IsMouseCaptured && ResizeMode == ResizeMode.CanResize)
                    {
                        var cursorLocation = e.GetPosition(this);

                        var nHorizontalChange = (cursorLocation.X - _cursorOffset.X);
                        var pHorizontalChange = (cursorLocation.X + _cursorOffset.X);
                        var nVerticalChange = (cursorLocation.Y - _cursorOffset.Y);
                        var pVerticalChange = (cursorLocation.Y + _cursorOffset.Y);

                        switch (borderEdge)
                        {
                            case WindowBorderEdge.Left:
                                if (Width - nHorizontalChange <= MinWidth) break;
                                Left += nHorizontalChange;
                                Width -= nHorizontalChange;
                                break;
                            case WindowBorderEdge.TopLeft:
                                if (!(Width - nHorizontalChange <= MinWidth))
                                {
                                    Left += nHorizontalChange;
                                    Width -= nHorizontalChange;
                                }
                                if (!(Height - nVerticalChange <= MinHeight))
                                {
                                    Top += nVerticalChange;
                                    Height -= nVerticalChange;
                                }
                                break;
                            case WindowBorderEdge.Top:
                                if (Height - nVerticalChange <= MinHeight) break;
                                Top += nVerticalChange;
                                Height -= nVerticalChange;
                                break;
                            case WindowBorderEdge.TopRight:
                                if (!(pHorizontalChange <= MinWidth))
                                {
                                    Width = pHorizontalChange;
                                }
                                if (!(Height - nVerticalChange <= MinHeight))
                                {
                                    Top += nVerticalChange;
                                    Height -= nVerticalChange;
                                }
                                break;
                            case WindowBorderEdge.Right:
                                if (pHorizontalChange <= MinWidth) break;
                                Width = pHorizontalChange;
                                break;
                            case WindowBorderEdge.BottomRight:
                                if (!(pHorizontalChange <= MinWidth))
                                {
                                    Width = pHorizontalChange;
                                }
                                if (!(pVerticalChange <= MinHeight))
                                {
                                    Height = pVerticalChange;
                                }
                                break;
                            case WindowBorderEdge.Bottom:
                                if (pVerticalChange <= MinHeight) break;
                                Height = pVerticalChange;
                                break;
                            case WindowBorderEdge.BottomLeft:
                                if (!(Width - nHorizontalChange <= MinWidth))
                                {
                                    Left += nHorizontalChange;
                                    Width -= nHorizontalChange;
                                }
                                if (!(pVerticalChange <= MinHeight))
                                {
                                    Height = pVerticalChange;
                                }

                                break;
                        }
                    }
                };
            #endregion

            #region MouseLeftButtonUp
            border.MouseLeftButtonUp += (sender, e) => border.ReleaseMouseCapture();
            #endregion
        }
예제 #3
0
        private void RegisterBorderEvents(WindowBorderEdge borderEdge, FrameworkElement border)
        {
            border.MouseEnter += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize)
                {
                    switch (borderEdge)
                    {
                        case WindowBorderEdge.Left:
                        case WindowBorderEdge.Right:
                            border.Cursor = Cursors.SizeWE;
                            break;
                        case WindowBorderEdge.Top:
                        case WindowBorderEdge.Bottom:
                            border.Cursor = Cursors.SizeNS;
                            break;
                        case WindowBorderEdge.TopLeft:
                        case WindowBorderEdge.BottomRight:
                            border.Cursor = Cursors.SizeNWSE;
                            break;
                        case WindowBorderEdge.TopRight:
                        case WindowBorderEdge.BottomLeft:
                            border.Cursor = Cursors.SizeNESW;
                            break;
                    }
                }
                else
                {
                    border.Cursor = Cursors.Arrow;
                }
            };

            border.MouseLeftButtonDown += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize)
                {
                    Point cursorLocation = e.GetPosition(this);
                    Point cursorOffset = new Point();

                    switch (borderEdge)
                    {
                        case WindowBorderEdge.Left:
                            cursorOffset.X = cursorLocation.X;
                            break;
                        case WindowBorderEdge.TopLeft:
                            cursorOffset.X = cursorLocation.X;
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.Top:
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.TopRight:
                            cursorOffset.X = (Width - cursorLocation.X);
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.Right:
                            cursorOffset.X = (Width - cursorLocation.X);
                            break;
                        case WindowBorderEdge.BottomRight:
                            cursorOffset.X = (Width - cursorLocation.X);
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                        case WindowBorderEdge.Bottom:
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                        case WindowBorderEdge.BottomLeft:
                            cursorOffset.X = cursorLocation.X;
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                    }

                    this.cursorOffset = cursorOffset;

                    border.CaptureMouse();
                }
            };

            border.MouseMove += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && border.IsMouseCaptured && ResizeMode == ResizeMode.CanResize)
                {
                    Point cursorLocation = e.GetPosition(this);

                    double nHorizontalChange = (cursorLocation.X - cursorOffset.X);
                    double pHorizontalChange = (cursorLocation.X + cursorOffset.X);
                    double nVerticalChange = (cursorLocation.Y - cursorOffset.Y);
                    double pVerticalChange = (cursorLocation.Y + cursorOffset.Y);

                    switch (borderEdge)
                    {
                        case WindowBorderEdge.Left:
                            if (Width - nHorizontalChange <= MinWidth)
                                break;
                            Left += nHorizontalChange;
                            Width -= nHorizontalChange;
                            break;
                        case WindowBorderEdge.TopLeft:
                            if (Width - nHorizontalChange <= MinWidth)
                                break;
                            Left += nHorizontalChange;
                            Width -= nHorizontalChange;
                            if (Height - nVerticalChange <= MinHeight)
                                break;
                            Top += nVerticalChange;
                            Height -= nVerticalChange;
                            break;
                        case WindowBorderEdge.Top:
                            if (Height - nVerticalChange <= MinHeight)
                                break;
                            Top += nVerticalChange;
                            Height -= nVerticalChange;
                            break;
                        case WindowBorderEdge.TopRight:
                            if (pHorizontalChange <= MinWidth)
                                break;
                            Width = pHorizontalChange;
                            if (Height - nVerticalChange <= MinHeight)
                                break;
                            Top += nVerticalChange;
                            Height -= nVerticalChange;
                            break;
                        case WindowBorderEdge.Right:
                            if (pHorizontalChange <= MinWidth)
                                break;
                            Width = pHorizontalChange;
                            break;
                        case WindowBorderEdge.BottomRight:
                            if (pHorizontalChange <= MinWidth)
                                break;
                            Width = pHorizontalChange;
                            if (pVerticalChange <= MinHeight)
                                break;
                            Height = pVerticalChange;
                            break;
                        case WindowBorderEdge.Bottom:
                            if (pVerticalChange <= MinHeight)
                                break;
                            Height = pVerticalChange;
                            break;
                        case WindowBorderEdge.BottomLeft:
                            if (Width - nHorizontalChange <= MinWidth)
                                break;
                            Left += nHorizontalChange;
                            Width -= nHorizontalChange;
                            if (pVerticalChange <= MinHeight)
                                break;
                            Height = pVerticalChange;
                            break;
                    }
                }
            };

            border.MouseLeftButtonUp += (sender, e) =>
            {
                border.ReleaseMouseCapture();
            };
        }
예제 #4
0
        private void RegisterBordersEvents(WindowBorderEdge borderEdge, FrameworkElement border)
        {
            border.MouseEnter += (sender, args) =>
            {
                if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize)
                {
                    switch (borderEdge)
                    {
                    case WindowBorderEdge.Left:
                    case WindowBorderEdge.Right:       border.Cursor = Cursors.SizeWE;   break;

                    case WindowBorderEdge.Top:
                    case WindowBorderEdge.Bottom:      border.Cursor = Cursors.SizeNS;   break;

                    case WindowBorderEdge.TopLeft:
                    case WindowBorderEdge.BottomRight: border.Cursor = Cursors.SizeNWSE; break;

                    case WindowBorderEdge.TopRight:
                    case WindowBorderEdge.BottomLeft:  border.Cursor = Cursors.SizeNESW; break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(borderEdge), borderEdge, null);
                    }
                }
                else
                {
                    border.Cursor = Cursors.Arrow;
                }
            };

            border.MouseLeftButtonDown += (sender, args) =>
            {
                if (WindowState == WindowState.Maximized || ResizeMode != ResizeMode.CanResize)
                {
                    return;
                }

                var cursorLocation = args.GetPosition(this);
                var cursorOffset   = new Point();

                switch (borderEdge)
                {
                case WindowBorderEdge.Left:        cursorOffset.X = cursorLocation.X;                                                     break;

                case WindowBorderEdge.TopLeft:     cursorOffset.X = cursorLocation.X;         cursorOffset.Y = cursorLocation.Y;          break;

                case WindowBorderEdge.Top:                                                    cursorOffset.Y = cursorLocation.Y;          break;

                case WindowBorderEdge.TopRight:    cursorOffset.X = Width - cursorLocation.X; cursorOffset.Y = cursorLocation.Y;          break;

                case WindowBorderEdge.Right:       cursorOffset.X = Width - cursorLocation.X;                                             break;

                case WindowBorderEdge.BottomRight: cursorOffset.X = Width - cursorLocation.X; cursorOffset.Y = Height - cursorLocation.Y; break;

                case WindowBorderEdge.Bottom:                                                 cursorOffset.Y = Height - cursorLocation.Y; break;

                case WindowBorderEdge.BottomLeft:  cursorOffset.X = cursorLocation.X;         cursorOffset.Y = Height - cursorLocation.Y; break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(borderEdge), borderEdge, null);
                }

                cursorOffset2 = cursorOffset;

                border.CaptureMouse();
            };

            border.MouseMove += (sender, args) =>
            {
                if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize && border.IsMouseCaptureWithin)
                {
                    var cursorLocation = args.GetPosition(this);

                    var nHorizontalChange = cursorLocation.X - cursorOffset2.X;
                    var pHorizontalChange = cursorLocation.X + cursorOffset2.X;
                    var nVerticalChange   = cursorLocation.Y - cursorOffset2.Y;
                    var pVerticalChange   = cursorLocation.Y + cursorOffset2.Y;

                    switch (borderEdge)
                    {
                    case WindowBorderEdge.Left:
                    {
                        if (!(Width - nHorizontalChange <= MinWidth))
                        {
                            Left  += nHorizontalChange;
                            Width -= nHorizontalChange;
                        }

                        break;
                    }

                    case WindowBorderEdge.TopLeft:
                    {
                        if (!(Width - nHorizontalChange <= MinWidth))
                        {
                            Left  += nHorizontalChange;
                            Width -= nHorizontalChange;
                        }

                        if (!(Height - nVerticalChange <= MinHeight))
                        {
                            Top    += nVerticalChange;
                            Height -= nVerticalChange;
                        }

                        break;
                    }

                    case WindowBorderEdge.Top:
                    {
                        if (!(Height - nVerticalChange <= MinHeight))
                        {
                            Top    += nVerticalChange;
                            Height -= nVerticalChange;
                        }

                        break;
                    }

                    case WindowBorderEdge.TopRight:
                    {
                        if (!(pHorizontalChange <= MinWidth))
                        {
                            Width = pHorizontalChange;
                        }

                        if (!(Height - nVerticalChange <= MinHeight))
                        {
                            Top    += nHorizontalChange;
                            Height -= nVerticalChange;
                        }

                        break;
                    }

                    case WindowBorderEdge.Right:
                    {
                        if (!(pHorizontalChange <= MinWidth))
                        {
                            Width = pHorizontalChange;
                        }

                        break;
                    }

                    case WindowBorderEdge.BottomRight:
                    {
                        if (!(pHorizontalChange <= MinWidth))
                        {
                            Width = pHorizontalChange;
                        }

                        if (!(pVerticalChange <= MinHeight))
                        {
                            Height = pVerticalChange;
                        }

                        break;
                    }

                    case WindowBorderEdge.Bottom:
                    {
                        if (!(pVerticalChange <= MinHeight))
                        {
                            Height = pVerticalChange;
                        }

                        break;
                    }

                    case WindowBorderEdge.BottomLeft:
                    {
                        if (!(Width - nHorizontalChange <= MinWidth))
                        {
                            Left  += nHorizontalChange;
                            Width -= nHorizontalChange;
                        }

                        if (!(pVerticalChange <= MinHeight))
                        {
                            Height = pVerticalChange;
                        }

                        break;
                    }

                    default:
                        throw new ArgumentOutOfRangeException(nameof(borderEdge), borderEdge, null);
                    }
                }
            };

            border.MouseLeftButtonUp += (sender, args) => {
                border.ReleaseMouseCapture();
            };
        }
예제 #5
0
        private void RegisterBorderEvents(WindowBorderEdge borderEdge, FrameworkElement border)
        {
            border.MouseEnter += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize)
                {
                    switch (borderEdge)
                    {
                    case WindowBorderEdge.Left:
                    case WindowBorderEdge.Right:
                        border.Cursor = Cursors.SizeWE;
                        break;

                    case WindowBorderEdge.Top:
                    case WindowBorderEdge.Bottom:
                        border.Cursor = Cursors.SizeNS;
                        break;

                    case WindowBorderEdge.TopLeft:
                    case WindowBorderEdge.BottomRight:
                        border.Cursor = Cursors.SizeNWSE;
                        break;

                    case WindowBorderEdge.TopRight:
                    case WindowBorderEdge.BottomLeft:
                        border.Cursor = Cursors.SizeNESW;
                        break;
                    }
                }
                else
                {
                    border.Cursor = Cursors.Arrow;
                }
            };

            border.MouseLeftButtonDown += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize)
                {
                    Point cursorLocation = e.GetPosition(this);
                    Point cursorOffset   = new Point();

                    switch (borderEdge)
                    {
                    case WindowBorderEdge.Left:
                        cursorOffset.X = cursorLocation.X;
                        break;

                    case WindowBorderEdge.TopLeft:
                        cursorOffset.X = cursorLocation.X;
                        cursorOffset.Y = cursorLocation.Y;
                        break;

                    case WindowBorderEdge.Top:
                        cursorOffset.Y = cursorLocation.Y;
                        break;

                    case WindowBorderEdge.TopRight:
                        cursorOffset.X = (Width - cursorLocation.X);
                        cursorOffset.Y = cursorLocation.Y;
                        break;

                    case WindowBorderEdge.Right:
                        cursorOffset.X = (Width - cursorLocation.X);
                        break;

                    case WindowBorderEdge.BottomRight:
                        cursorOffset.X = (Width - cursorLocation.X);
                        cursorOffset.Y = (Height - cursorLocation.Y);
                        break;

                    case WindowBorderEdge.Bottom:
                        cursorOffset.Y = (Height - cursorLocation.Y);
                        break;

                    case WindowBorderEdge.BottomLeft:
                        cursorOffset.X = cursorLocation.X;
                        cursorOffset.Y = (Height - cursorLocation.Y);
                        break;
                    }

                    this.cursorOffset = cursorOffset;

                    border.CaptureMouse();
                }
            };

            border.MouseMove += (sender, e) =>
            {
                if (WindowState != WindowState.Maximized && border.IsMouseCaptured && ResizeMode == ResizeMode.CanResize)
                {
                    Point cursorLocation = e.GetPosition(this);

                    double nHorizontalChange = (cursorLocation.X - cursorOffset.X);
                    double pHorizontalChange = (cursorLocation.X + cursorOffset.X);
                    double nVerticalChange   = (cursorLocation.Y - cursorOffset.Y);
                    double pVerticalChange   = (cursorLocation.Y + cursorOffset.Y);

                    switch (borderEdge)
                    {
                    case WindowBorderEdge.Left:
                        if (Width - nHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Left  += nHorizontalChange;
                        Width -= nHorizontalChange;
                        break;

                    case WindowBorderEdge.TopLeft:
                        if (Width - nHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Left  += nHorizontalChange;
                        Width -= nHorizontalChange;
                        if (Height - nVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Top    += nVerticalChange;
                        Height -= nVerticalChange;
                        break;

                    case WindowBorderEdge.Top:
                        if (Height - nVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Top    += nVerticalChange;
                        Height -= nVerticalChange;
                        break;

                    case WindowBorderEdge.TopRight:
                        if (pHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Width = pHorizontalChange;
                        if (Height - nVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Top    += nVerticalChange;
                        Height -= nVerticalChange;
                        break;

                    case WindowBorderEdge.Right:
                        if (pHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Width = pHorizontalChange;
                        break;

                    case WindowBorderEdge.BottomRight:
                        if (pHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Width = pHorizontalChange;
                        if (pVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Height = pVerticalChange;
                        break;

                    case WindowBorderEdge.Bottom:
                        if (pVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Height = pVerticalChange;
                        break;

                    case WindowBorderEdge.BottomLeft:
                        if (Width - nHorizontalChange <= MinWidth)
                        {
                            break;
                        }
                        Left  += nHorizontalChange;
                        Width -= nHorizontalChange;
                        if (pVerticalChange <= MinHeight)
                        {
                            break;
                        }
                        Height = pVerticalChange;
                        break;
                    }
                }
            };

            border.MouseLeftButtonUp += (sender, e) =>
            {
                border.ReleaseMouseCapture();
            };
        }