title: Finding the selected item in an ItemsControl when the PreviewMouseLeftButtonDownCommand RelayCommand\EventToCommand fires
body: <p>My app is wpf mvvm, using RelayCommand\EventToCommand bindings for the events. My app does some typical drag &amp; drop from a ListBox onto an ItemsControl (it is actually an image control with an ItemsControl on top, that is holding the dropped items). The ListBox is populated with a vm ObservableCollection. And the ItemsControl is also an ObservableCollection that I insert the dropped MyObj items into. </p>
  
  <p>When I drag items from the ListBox and drop them in to\on to the ItemsControl\image it all works fine. In the PreviewMouseLeftButtonDownCommand I use the System.Windows.Media.VisualTreeHelper to recursively walk up the visual tree, so when I drag from the ListBox I can find the MyObj item that is being dragged. But when I try drag an item from the ItemsControl the code does not work. All I can get back is the DataTemplate conversion of the item (a lable). So my question is; how do I get the selected item from my ItemsControl when the PreviewMouseLeftButtonDownCommand RelayCommand\EventToCommand fires?</p>
  
  <p>the vm C#:</p>
  
  <pre><code>PreviewMouseLeftButtonDownCommand = new RelayCommand&lt;MouseButtonEventArgs&gt;(e =&gt;
  {
      if (e.Source is ListBox)
      {
      // get dragged list box item
      ListBox listBox = e.Source as ListBox;
      ListBoxItem listBoxItem = VisualHelper.FindAncestor&lt;ListBoxItem&gt;((DependencyObject)e.OriginalSource);
  
      // Find the data behind the listBoxItem
      if (listBox == null || listBoxItem == null) return;
  
      MyObj tag = (MyObj)listBox.ItemContainerGenerator.ItemFromContainer(listBoxItem);
  
       // Initialize the drag &amp; drop operation
      DataObject dragData = new DataObject("myObj", tag);
      DragDrop.DoDragDrop(listBoxItem, dragData, DragDropEffects.Move);
  }
  else if (e.Source is ItemsControl)
  {
      ItemsControl itemsControl = e.Source as ItemsControl;
      object item = VisualHelper.FindAncestor&lt;UIElement&gt;((DependencyObject)e.OriginalSource);
  
      if (itemsControl == null || item == null) return;
  
      MyObj tag = (MyObj)itemsControl.ItemContainerGenerator.ItemFromContainer(item);
  
  
      // Initialize the drag &amp; drop operation
      DataObject dragData = new DataObject("myObj", tagDragging);
      DragDrop.DoDragDrop(item, dragData, DragDropEffects.Move);
      }
  });
  </code></pre>