I found a solution but I'm hoping that there is a easier way. :)
This is what I did.
I started by simplying the problem. I created a single drop target and a single drag source. In the loaded event I implemented this code:
void MainPage_Loaded(object sender, RoutedEventArgs e)
myDragSource.DropTargets = new List<DropTarget>();
This worked so basically I had to initialise the DragTargets list and then manually add my DropTarget to the list.
Using this I now had to implemented the same thing but with 2 listbox controls (back to my original problem). This was more difficult as I found it hard to access the controls within the listbox templete. Below is how I resolved.
Firstly I created a list of DropTargets that I can use later when the DragSources are moved.
List<DropTarget> dropTargets = new List<DropTarget>();
I then created a event for the DropTarget Loaded and in this event I add the Drop Targets as they get created.
private void DropTargetLocation_Loaded(object sender, RoutedEventArgs e)
DropTarget dt = sender as DropTarget;
I also needed to clear out the list of drop targets just before I bind my ItemsSource for the listbox:
I then created a Loaded event handler for the DragSource and in this method I add all the DropTargets in my list (dropTargets) into the DropTargets list of the DragSource.
private void DragSourceMotor_Loaded(object sender, DragEventArgs args)
DragSource ds = sender as DragSource;
if (ds.DropTargets == null)
ds.DropTargets = new List<DropTarget>();
foreach (DropTarget dt in dropTargets)
This works but it is a lot of work.
Anyway, its a solution but it would be good if there was a better way.