Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: How to implement Drag and Drop with nested (hierarchical) controls

Using WPF I've succeeded at implementing drag and drop to rearrange items within a list(view or box) and also to drag and drop items between lists.

Now I am trying figure out how to implement drag and drop with NESTED lists.

For instance I have a listview containing projects and each project item contains another listview of tasks. I want to be able to drag and drop to rearrange the order of projects and also to reorder tasks and move them between projects.

I have code that successfully does one of the other, but I can't figure out how to do both.

It seems like there is some sort of painful solution that would involve hit testing and maybe the z-order of the nested lists, but I can't find any examples of this.

Can anybody offer any pointers?

FYI: The working code that I currently have implemented is based on the following two excellent articles on WPF drag and drop:

http://bea.stollnitz.com/blog/?p=53 http://www.codeproject.com/KB/WPF/ListViewDragDropManager.aspx

like image 923
Scrappydog Avatar asked Feb 20 '09 22:02

Scrappydog


2 Answers

Since MouseMove and most others in wpf are routed events, you could just check e.OriginalSource in a common event handler. Then you can decide which element to drag based on which element the mouse was on, probably using one of those "find parent which satisfies condition" helper method techniques. Additionally, you can set e.Handled if you have several elements in the visual tree subscribing to the event.

like image 160
Kenan E. K. Avatar answered Oct 23 '22 05:10

Kenan E. K.


Just first thoughts is, why not use a TreeView instead of a ListView if you're going to have nesting?

like image 21
Davy8 Avatar answered Oct 23 '22 03:10

Davy8