引用:System.Windows.Controls.Toolkit
xmlns:mswindows="clr-namespace:Microsoft.Windows;assembly=System.Windows.Controls.Toolkit"
然后用ListBoxDragDropTarget套在ListBox外,并设置ItemsPanelTemplate。
----ListBoxDragDropTarget并不能作用于virtualized容器(ListBox的默认容器),所以必须改变ListBox的ItemsPanelTemplate容器,比如说像这样加个StackPanel进去取代virtualized默认容器即可 .
<toolKit:ListBoxDragDropTarget AllowDrop="True">
<ListBox x:Name="AcceptListBox" Height="200" Width="200" DisplayMemberPath="Name">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</toolKit:ListBoxDragDropTarget>
除了ListBoxDragDropTarget控件还有如下控件也支持这种效果:
ListBoxDragDropTarget[已实现]
TreeViewDragDropTarget -[实现Treeview拖拽]
DataGridDragDropTarget-[DataGrid控件支持]
DataPointSeriesDragDropTarget-[尚未测试.]
原文地址:http://www.cnblogs.com/chenkai/archive/2010/05/26/1744226.html