Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何确定DragSource中的Drop事件_C#_Wpf_Drag And Drop - Fatal编程技术网

C# 如何确定DragSource中的Drop事件

C# 如何确定DragSource中的Drop事件,c#,wpf,drag-and-drop,C#,Wpf,Drag And Drop,我有一个列表框,其中包含一些文本值 <ListBox x:Name="DragSource" PreviewMouseMove="DragSource_OnPreviewMouseMove" SelectedValuePath="Content"> <ListBoxItem>first</ListBoxItem> <ListBoxItem>second</ListBoxItem> </ListBox> 可以将项目

我有一个列表框,其中包含一些文本值

<ListBox x:Name="DragSource" PreviewMouseMove="DragSource_OnPreviewMouseMove" SelectedValuePath="Content">
  <ListBoxItem>first</ListBoxItem>
  <ListBoxItem>second</ListBoxItem>
 </ListBox>

可以将项目拖放到“我的其他列表框”或其他应用程序(如Word或Excel)中。如果DragDrop效果为“移动”,我如何检测文本被删除(例如Word)并删除ListBoxItem?

没有第三方应用程序会告诉您它移动了ListBoxItem。充其量它将使用文本表示并告诉您它是复制的。获得移动需要一个drop目标,该目标可以在其DragEnter事件处理程序中识别您的对象,并确定它可以对此负责。只有您才能编写这样的事件处理程序。

我的dragsource提供了反馈和QueryContinueDrag事件,在这里我可以找到现在应用的效果。QueryContinueDragEventArgs具有可以取消、删除或继续的操作。但我只收到Continue event.QCD,它只允许您在键盘或鼠标状态更改时更改D+D。是,操作设置为继续,因为这是默认设置。赋值结束D+D。
private void DragSource_OnPreviewMouseMove(object sender, MouseEventArgs e)
{
 if (e.LeftButton == MouseButtonState.Pressed && DragSource.SelectedItem != null)
 {
  var data = new DataObject(DataFormats.Serializable, DragSource.SelectedItem);
  var value = (string)DragSource.SelectedValue;
  data.SetData(DataFormats.Text, value);
  var de = DragDrop.DoDragDrop(DragSource, data, DragDropEffects.All);
 }
}