title: WPF MVVM - Command binding inside of an ItemsControl
body: <p>I'm currently converting a small WPF project to MVVM.  I have a <code>List&lt;CustomObject&gt;</code> in the ViewModel of the main window that my ItemsControl binds to and uses a DataTemplate to build the UI of each element.  My old code used an event handler inside the DataTemplate to handle a click event.  I want to use some kind of command binding to eliminate my code-behind event handlers, but the DataContext of the items in my ItemsControl is the model object so I can't currently bind to an ICommand from the ViewModel.</p>
  
  <p>So, I guess there are a couple of ways to attack this and I'm not sure which would be the most "MVVM" way of doing it.  Do I bind the ItemsControl.ItemsSource to a collection of a new ViewModel class that represents each item?  Or do I use UserControls instead of a DataTemplate and then I can bind each UserControl to it's own instance of a ViewModel that represents it?  Or is there some kind of binding expression I can use to refer back to the DataContext of the window to have access to bind to the ViewModel (as I type this, it just sounds bad so I'm assuming a big "NO" to this idea)?</p>
  
  <p>Also, what I want to bind my command to is the LeftMouseButtonUp event of a Grid control.  There's no "Command" for a Grid, so I was attempting to use InputBindings.  I could use a static command (such as one of the built in ApplicationCommands), but I could not use a binding expression to bind to an ICommand instance that is a property of the ViewModel because MouseBinding.Command is not a DependencyProperty.</p>
  
  <p>I'm pretty confused on the subject of event handling in MVVM, so any and all info is appreciated.</p>