Drag and Drop with TreeView Children

108 views
Skip to first unread message

Matt Starn

unread,
Jul 25, 2011, 2:27:52 PM7/25/11
to gong-wpf-dragdrop
I'm trying to implement a drag and drop solution in this manner:

I have a ViewModel that implements two ObservableCollections. One is
bound to a TreeView, one is bound to a standard ItemsControl within a
UserControl that is on the same window, same application as the
TreeView. My goal is to try to make the third tier of the TreeView's
items draggable but not all the items. My treeview is dynamic and is
dependent on the type of file some user might insert, but will always
have a strict tiering system (Type A is a parent of Type B, which is a
parent of Type C, and Type C is what I'm trying to make draggable). I
set up a tiered Hierarchical Data Template in such a way to display
Type A and Type B items in the treeview as regular textblocks, and
Type C is a stylized Label within a Border (to make it more apparent
this is the item we're dragging). These are all templated within the
grid resources where the TreeView and ItemsControl exists.

Anyway, now that that's been explained, down to the nitty-gritty of
the issue at hand. If I use the IsDragSource property within the Label
definition of child type I want to make draggable, then nothing
happens at all. The solution runs, but I can't drag a single thing
when my TreeView is established. If I change the property to be
defined within the definition of the TreeView, then the Border/Label
childs are draggable (as well as the TextBlocks, although I don't want
this) and if I try to drag something over to the ItemsControl then a
NullReferenceException is thrown at Line 29 of DropInfo.cs (where it
is trying to find the index of the ItemParent).

I should clarify that this is my first time attempting to use drag and
drop for a WPF project, so I'm new at attempting something like this.
Hope to hear a response soon. I can clarify certain points within the
project if you have any questions.
Reply all
Reply to author
Forward
0 new messages