C# WPF快速单击事件变为拖动事件

C# WPF快速单击事件变为拖动事件,c#,.net,wpf,C#,.net,Wpf,我有一个问题,快速点击会变成一个拖拽事件 Vector d = _pointStartDrag - e.GetPosition(null); if( |d.x| > minDx || |d.y| > minDy) //here is my drag-event 我使用preventMouseButtonDown事件获取开始位置: private void previewMouseLeftButtonDown(object sender, MouseButtonEventAr

我有一个问题,快速点击会变成一个拖拽事件

Vector d = _pointStartDrag - e.GetPosition(null);
if( |d.x| > minDx || |d.y| > minDy)
    //here is my drag-event
我使用preventMouseButtonDown事件获取开始位置:

private void previewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    _pointStartDrag = e.GetPosition(null);
}
previewMouseMove事件提供实际位置。我比较这两个点来触发我的拖动事件

Vector d = _pointStartDrag - e.GetPosition(null);
if( |d.x| > minDx || |d.y| > minDy)
    //here is my drag-event
无论设置了什么minDx/y,都可以通过在我的gui上快速单击两个不同的点来实现


我不知道出了什么问题。有什么想法吗?

我一两天前刚刚回答了这个问题,但我现在找不到问题,所以我再做一次。为此,您可以使用
SystemParameters.MinimumHorizontalDragDistance
SystemParameters.MinimumVerticalDragDistance
属性:

private bool IsConfirmedDrag(Point point)
{
    bool horizontalMovement = Math.Abs(point.X - dragStartPosition.X) > 
        SystemParameters.MinimumHorizontalDragDistance;
    bool verticalMovement = Math.Abs(point.Y - dragStartPosition.Y) > 
        SystemParameters.MinimumVerticalDragDistance;
    return (horizontalMovement | verticalMovement);
}
它是这样使用的:

private void DragSourcePreviewMouseMove(object sender, MouseEventArgs e)
{
    if (isMouseDown && IsConfirmedDrag(e.GetPosition(sender as ListBox)))
    {
        isMouseDown = false;
        ...
        // Start Drag operation
    }
}

为什么不使用?Thx,我来检查:)tyvm,我来试试。