开发者

How to determine Drop event in DragSource

I have a Listbox, that contains some text values

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

and event handler

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);
 }
}

Items can be dropped to my other ListBox or into other application like Word or Excel. How i can detect that text was开发者_运维技巧 dropped (for example in Word) and delete ListBoxItem if DragDrop effect is "Move"?


No 3rd party app is going to tell you that it moved your ListBoxItem. At best it will use the text representation and tell you it copied. Getting a move requires a drop target that can recognize your object in its DragEnter event handler and decide that it can take responsibility for it. Only you could write such an event handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜