title: Binding Button click to a method
body: <p>I have a datagrid bound to an observable collection of objects.  What I want to do is have a button that will execute a method of the object representing the row of the button that was clicked.  So what I have now is something like this:</p>
  
  <pre><code>            &lt;DataGridTemplateColumn Header="Command"&gt;
                  &lt;DataGridTemplateColumn.CellTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;Button Name="cmdCommand" Click="{Binding Command}" 
                                  Content="Command"/&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/DataGridTemplateColumn.CellTemplate&gt;
              &lt;/DataGridTemplateColumn&gt;
  </code></pre>
  
  <p>Which doesn't work and reports the following error:</p>
  
  <p>Click="{Binding Command}" is not valid. '{Binding Command}' is not a valid event handler method name. Only instance methods on the generated or code-behind class are valid.</p>
  
  <p>I've looked at command binding but that looks like it would just end up going to a single external command instead of to the object bound to the row.  I have it working using an event handler on the code behind and then routing it to the item bound to the selected row (since the row gets selected when the button is clicked) but that seems like poor way of handing this and I assume I'm just missing something here.</p>