我目前正在改进我的 wpf 应用程序中的拖放功能。因此,我想让源控件知道用户何时将数据放在目标控件上。我认为这种目标的机制是由 QueryContinueDrag 事件提供的。实际上,我能够成功设置 QueryContinueDrag 事件的集成:
private void TrvImport_OnPreviewMouseMove(object sender, MouseEventArgs e)
{
Point mousePos = e.GetPosition(null);
Vector diff = startPoint - mousePos;
if (e.LeftButton == MouseButtonState.Pressed
&& (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance
|| Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
{
MailBox transportBox = new MailBox();
transportBox.DocumentList = new ObservableCollection<Domain.Document>();
DataObject dragData = new DataObject("MailBox", transportBox);
DragDrop.DoDragDrop(TrvImport, dragData, DragDropEffects.All);
}
}
现在,只要我开始拖放,就会定期执行下面的事件方法。但是,当我通过释放鼠标按钮完成拖放时,不会再次使用e.Action == DragAction.Drop参数触发事件 - 正如我所期望的那样。为什么?
private void TrvImport_OnQueryContinueDrag(object sender, QueryContinueDragEventArgs e)
{
if (e.Action != DragAction.Continue)
{
Console.WriteLine("This Line is never executed, why?");
}
}