c# - MouseButton.LeftButton 在拖放过程中错误地报告为释放 GiveFeedback

标签 c# .net wpf drag-and-drop

不确定为什么会这样。我在拖放时订阅了 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/

相关文章:

c# - 录音机 c# UWP

c# - protected 构造函数 - 不与 GetConstructors() 一起显示

c# - 在不违反 MVVM 的情况下将集合绑定(bind)到 ListBox 中的 SelectedItems

c# - 自动完成框 - 总体值不一致

c# - 在字符串中找到特定的单词并打印剩余的行

c# - MySQL 连接字符串 C#

.net - .net 中的事件签名模式

javascript - React JS/Typescript 中的空合并运算符

C++ 表达式必须具有类类型 - String 到 const char*

c# - 更改 DataGrid Cell WPF 关于范围的颜色