title: Silverlight 5 Treeview Drag and Drop
body: <p>I'm having issues doing Drag and Drop with a TreeView in SilverLight.  I want to be able to reorder items in a TreeView.  For example, reparent an item.  I am using EntityFramework with a hierarchical relationship (ID, ParentID).  Here is my xaml.</p>
  
  <pre><code>&lt;toolkit:TreeViewDragDropTarget AllowDrop="True" HorizontalAlignment="Left"&gt;
     &lt;sdk:TreeView Name="treeView1" Height="176" 
          HorizontalAlignment="Left" Width="Auto"&gt;
        &lt;sdk:TreeView.ItemTemplate&gt;
           &lt;sdk:HierarchicalDataTemplate 
                ItemsSource="{Binding Path=Children}"&gt;
              &lt;TextBlock Text="{Binding Path=LocationName}"/&gt;
           &lt;/sdk:HierarchicalDataTemplate&gt;
        &lt;/sdk:TreeView.ItemTemplate&gt;
     &lt;/sdk:TreeView&gt;
  &lt;/toolkit:TreeViewDragDropTarget&gt;
  </code></pre>
  
  <p>I created some Event Handlers to see if the drag and drop events were working and they were.  Silverlight also give visual feedback that the drag is happening.  </p>
  
  <p>One thing I wonder about is that the Collection that is bound to the TreeView is not an ObservableCollection.  The Children property of the Entity is an EntityCollection.  I'm not sure what I can mess with in the EntityObject.</p>
  
  <p>Anyone have any ideas??</p>
  
  <p>UPDATE:  If I drag a child node to any node in its upper or lower tree, nothing happens.  If I drag a child above or below a root node, a line appears in the tree view.  If I drop it there, I get a null reference exception.  I cannot pin it down.  I know there is a lot going on in this question, but I think we are getting close.  Any help or insight is appreciated.  </p>
  
  <p>UPDATE 2: I'll add some screen shots to show what is happening.</p>
  
  <p><img src="https://i.stack.imgur.com/wynpG.png" alt="This is a sample treeview.">
  Sample treeview</p>
  
  <p><img src="https://i.stack.imgur.com/pZVu9.png" alt="TreeViewItem Drag">
  This is what it looks like when I drag an item.  I'm trying to drag Milky Way to be a root node with no parent.  Notice the Line at the top.  I assume this is the drop location.  If I drop it there, I get the exception.  Let's say I drag Solar System to be a direct child of Universe.  Nothing happens.  No line appears either.</p>