This drag-and-drop manager for WPF handles both TreeViews and ListViews, and includes the following features:
The demo consists of a TreeView that holds categories, and a ListView populated with the selected category's items. These two controls together have a total of three types of drag-drop operations setup on them.
Click the "Download" button at the top of this page to get the demo. The drag-and-drop setup code in the demo look like this:
dragMgr.AddControl<Category>( categoriesTreeView );
dragMgr.AddControl<Item>( itemsListView );
dragMgr.AddHandler<Category>( categoriesTreeView, dragMgr_ProcessMove );
dragMgr.AddHandler<Item>( itemsListView, dragMgr_ProcessMove );
dragMgr.AddHandler<Item, Category>( categoriesTreeView, dragMgr_ProcessLink );
dragMgr.GetLinkEffect += dragMgr_GetLinkEffect;
The first two lines indicate which controls will have their dragging managed. The following three lines add the event handlers whose job is to actually move or link the domain-model objects. The last line adds the custom link animations you will see in the demo. The body of your ProcessMove and ProcessLink event handlers will depend on how you've architected your presentation-model. The demo app doesn't even use one, so the event handlers simply look like this:
void dragMgr_ProcessMove( object sender, MoveArgs<Category> moveArgs )
{
moveArgs.oldPosition.parent.SubCategories.Remove( moveArgs.itemToMove );
moveArgs.newPosition.parent.SubCategories.Insert(
moveArgs.newPosition.childIndex, moveArgs.itemToMove );
}
void dragMgr_ProcessMove( object sender, FlatMoveArgs<Item> moveArgs )
{
var category = (Category)categoriesTreeView.SelectedItem;
category.Items.RemoveAt( moveArgs.oldIndex );
category.Items.Insert( moveArgs.newIndex, moveArgs.itemToMove );
}
void dragMgr_ProcessLink( object sender, LinkArgs<Item, Category> e )
{
e.TargetLoc.Items.Add( e.ItemToLink );
}
Purchase DragDropManager for WPF by clicking here.