title: DataGrid Single Cell row and column from click using MVVM
body: <p>I have DataGrid and I am trying to get the cell details (column,row and value) of a selected cell using MVVM and avoid putting in any changes to the code behind.</p>
  
  <p>My data grid looks like this</p>
  
  <pre><code>&lt;DataGrid x:Name="MyDataGrid" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=MyData}" AutoGenerateColumns="False" IsReadOnly="True" GridLinesVisibility="None" SelectionUnit="Cell"&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTextColumn  Header="a" Width="130" Binding="{Binding Path=A}"/&gt;
          &lt;DataGridTextColumn  Header="b"   Width="100" Binding="{Binding Path=B}"/&gt;
          &lt;DataGridTextColumn  Header="c"   Width="100" Binding="{Binding Path=C}"/&gt;
      &lt;/DataGrid.Columns&gt;
      &lt;DataGrid.InputBindings&gt;
          &lt;MouseBinding Gesture="LeftClick"  Command="{Binding DataGridLeftClick}" CommandParameter="{Binding ElementName=MyDataGrid, Path=SelectedCells}" /&gt;
      &lt;/DataGrid.InputBindings&gt;
  </code></pre>
  
  <p>in my ViewModel I have</p>
  
  <pre><code>   DataGridLeftClick = new RelayCommand(LeftClick);
     ...
  
     public ICommand DataGridLeftClick { get; private set; }
  
     public void LeftClick(object obj)
     {   
         log.Info(obj);
     }
  </code></pre>
  
  <p>The command works but there are two things the value of obj is always null.  If I remove the SelectionUnit of the grid (so i assume it defaults to FullRow) then I get the data of the full rows cells.  How do I get the cell row,index and value of a single the cell that was clicked on?</p>
  
  <p>Thanks,
  Nick</p>