title: Drag & Drop in Treeview
body: <p>I'm trying to drag and drop files in my treeview but I have no idea why it's breaking down if I run it and try dragging a file.</p>
  
  <p>The code below is what I tried. Please help.</p>
  
  <pre><code>private void TreeViewItem_Drop( object sender, DragEventArgs e)
  {
      TreeViewItem treeViewItem = e.Source as TreeViewItem;
      TreeViewItem obj = e.Data.GetData(typeof(TreeViewItem)) as TreeViewItem;
  
      if ((obj.Parent as TreeViewItem) != null)
      {
          (obj.Parent as TreeViewItem).Items.Remove(obj);
      }
      else
      {
          treeViewItem.Items.Remove(obj);
          treeViewItem.Items.Insert(0, obj);
          e.Handled = true;
      }
  }
  
  private void TreeViewItem_MouseLeftButtonDown( object sender,MouseButtonEventArgs e)
  {
      DependencyObject dependencyObject = _treeview.InputHitTest(e.GetPosition(_treeview)) as DependencyObject;
  
      Debug.Write(e.Source.GetType().ToString());
  
      if (dependencyObject is TextBlock)
      {
          TreeViewItem treeviewItem = e.Source as TreeViewItem;
  
          DragDrop.DoDragDrop(_treeview, _treeview.SelectedValue, DragDropEffects.Move);
          e.Handled = true;
      }
  }
  </code></pre>