title: How to bind DataGrid.SelectedItem in DataTemplate
body: <p>Hope it's not a dup.  I'm using Silverlight 4.</p>
  
  <p>I have a collection <em>MyProjects</em> from my ViewModel <em>MyVM</em> binding to a datagrid <em>MainDataGrid</em>. </p>
  
  <p>I also have a RowDetailsTemplate to show several buttons. </p>
  
  <p>I have Command binding on these buttons.  The command binding <em>Command="{Binding Path=EditCommand}"</em> appears working but I just can't get the CommandParameter binding working.  Is Element name working inside a DataTemplate?  What's the best way to pass in SelectedItem/SelectedDataRow via a CommandParameter binding inside a DataTemplate?</p>
  
  <p>Thanks for your help. </p>
  
  <pre><code>        &lt;sdk:DataGrid x:Name="MainDataGrid" AutoGenerateColumns="False" DataContext="{StaticResource MyVM}" ItemsSource="{Binding MyProjects}" RowDetailsVisibilityMode="VisibleWhenSelected"&gt;
  
              &lt;sdk:DataGrid.RowDetailsTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Background="Ivory" Orientation="Horizontal"&gt;
                          &lt;Button Style="{StaticResource DataGridRowDetailsButtonStyle}"
                                  Command="{Binding Path=EditCommand}" 
                                  CommandParameter="{Binding ElementName=MainDataGrid, Path=SelectedItem}"&gt;Edit&lt;/Button&gt;
  </code></pre>