C# WPF - DragMove and click

前端 未结 2 1334
悲哀的现实
悲哀的现实 2020-12-21 16:23

I need a control to call DragMove() for a Window on MouseLeftButton down, but still function when clicked.

If DragMove() is called, Click and MouseLeftButtonUp are n

相关标签:
2条回答
  • 2020-12-21 16:46

    I believe my edit above is the best solution.

    0 讨论(0)
  • 2020-12-21 16:49

    If you want both behaviors then you will have to trap both the mouse down and mouse move events. In the mouse down you save the current mouse location:

    StartPosition = event.GetPosition(ui_element);
    

    Then in the mouse move you only start a drag if the mouse button is still down and the mouse has moved enough:

            if (e.LeftButton == MouseButtonState.Pressed) {
            Point position = e.GetPosition(Scope);
            if (Math.Abs(position.X - StartPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
                Math.Abs(position.Y - StartPoint.Y) > SystemParameters.MinimumVerticalDragDistance) {
                StartDrag(e);
            }
        }
    

    The SystemParameters object defines the Windows' idea of what a move is.

    0 讨论(0)
提交回复
热议问题