title: Preserve default WPF DataGrid cell editing behaviour when using DataGridTemplateColumn
body: <p>I am working on a WPF MVVM application that uses <code>DataGrids</code> to display data. I am manually defining the columns, and most of the time I use <code>DataGridTextColumn</code>.</p>
  
  <p>When navigating the resulting datagrid using the keyboard, a cell can be highlighted by navigating to it, and the cell value can be changed by starting to type a value. This behaviour works for <code>DataGridTextColumn</code>. </p>
  
  <p>In some cases, I have to use <code>DataGridTemplateColumn</code>, with different bindings for the <code>CellTemplate</code> and the <code>CellEditingTemplate</code>. This allows me to format the displayed value, but return to an unformatted value once the user starts editing the cell. However, the keyboard navigation and editing method described above does not work for my current implementation. I have to highlight the cell and press F2 to edit, or I have to click on the cell with the mouse.</p>
  
  <p>Below is a mockup of my current implementation, in which <code>Foo</code> is in a <code>DataGridTextColumn</code> which works fine, and <code>Bar</code> is in a <code>DataGridTemplateColumn</code> which is giving me trouble.</p>
  
  <p>How can I change the definition of my <code>DataGridTemplateColumn</code> so it has the same keyboard navigation and editing functionality as the <code>DataGridTextColumn</code>?</p>
  
  <pre><code>&lt;DataGrid ItemsSource="{Binding ListItems}"&gt;
      &lt;DataGrid.Columns&gt;
  
          &lt;DataGridTextColumn Binding="{Binding Foo}"
                              Header="Foo" /&gt;
  
          &lt;DataGridTemplateColumn Header="Bar"&gt;
              &lt;DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;ContentPresenter Content="{Binding Path=BarString, Mode=OneWay}"
                                        HorizontalAlignment="Right" /&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellTemplate&gt;
              &lt;DataGridTemplateColumn.CellEditingTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;TextBox Text="{Binding BarValue, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                               HorizontalContentAlignment="Right" /&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellEditingTemplate&gt;
          &lt;/DataGridTemplateColumn&gt;
  
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>