title: WPF: How to attach mouse events to a viewmodel?
body: <p>I am trying to use the MVVM pattern for the first time. So I have an <code>ItemsControl</code> filled with my viewmodel objects, displayed using <code>DataTemplate</code>'s; the objects are "nodes" and "edges" represented in <code>DataTemplate</code>'s with <code>Thumb</code> and <code>Polyline</code> objects and I want to be able to detect clicks and drags on the <code>ItemsControl</code> in order to move the nodes and edges.</p>
  
  <p>Two questions:</p>
  
  <ul>
  <li>How do I attach mouse event handlers to the <code>Polyline</code>'s and <code>Thumb</code>'s to be handled by the little viewmodels? (I could attach a <code>Thumb.DragDelta</code> handler to the <code>ItemsControl</code> and <code>e.OriginalSource</code> points to the <code>Thumb</code>, but how do I get the corresponding viewmodel object?)</li>
  <li>How do I attach mouse event handlers to the <code>ItemsControl</code> to detect mouse clicks and drags on blank space? (answer is below)</li>
  </ul>
  
  <p>Note: I know it might not be considered a proper ViewModel if it's directly handling events of the View. But the important point is, I need to handle mouse events and I am not sure how to attach them.</p>