不知道为什么会这样。进行拖放时,我正在订阅GiveFeedback。

在此GiveFeedback内部,我正在检查鼠标左键的状态。如果发布了,我想做“某事”(不重要)。

以下总是返回“鼠标按钮已释放”。

我的代码:

private void GiveDragFeedback(object sender, GiveFeedbackEventArgs args)
{
  var mouseArgs = new MouseEventArgs(Mouse.PrimaryDevice, 0);

  if (Mouse.LeftButton == MouseButtonState.Pressed)
    Console.WriteLine("Mouse Button PRESSED");
  else
    Console.WriteLine("Mouse Button RELEASED");

  if (Mouse.PrimaryDevice.LeftButton == MouseButtonState.Pressed)
    _adorner_MouseMove(sender, new MouseEventArgs(Mouse.PrimaryDevice, 0));
  else
    _adorner_MouseUp(sender, mouseArgs);
}

最佳答案

改为这样做:

 protected override void OnQueryContinueDrag(QueryContinueDragEventArgs e)
    {
        if (!e.KeyStates.HasFlag(DragDropKeyStates.LeftMouseButton))
        {
             e.Action = DragAction.Cancel;
        }
        else
        {
            e.Action = DragAction.Continue;
        }
    }

关于c# - MouseButton.LeftButton错误地报告了拖放拖放GiveFeedback期间释放的结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15799163/

10-09 08:49