2010-11-24 77 views
1

我有一個列表框Drop事件,包含一些文本值如何確定的DragSource

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

和事件處理

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

項目可以刪除我的其他列表框或到其它應用程序一樣Word或Excel。如果DragDrop效果是「Move」,我可以檢測到文本被丟棄(例如在Word中)並刪除ListBoxItem?

回答

2

沒有第三方應用程序會告訴你它移動了你的ListBoxItem。最好它會使用文本表示並告訴你它被複制。獲取移動需要一個放置目標,它可以在其DragEnter事件處理程序中識別您的對象,並決定它可以爲此負責。只有你可以編寫這樣的事件處理程序。

+0

我的dragsource有GiveFeedback和QueryContinueDrag事件,在這裏我可以找出現在應用的效果。 QueryContinueDragEventArgs具有可以取消,刪除或繼續的操作。但我只收到Continue事件。 – Steck 2010-11-25 08:22:34