title: How to focus and begin edit first cell of first row on page load of DataGrid
body: <p>I want to focus and begin edit first cell of first row when <code>UserControl</code> load or page load automatically. I've tried many code but wont find solution yet.I've write code for <code>DataGrid</code>:</p>
  
  <pre><code>&lt;UserControl x:Class="Inventory_Control.UserControls.FileTab"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               xmlns:local="clr-namespace:Inventory_Control.UserControls"
               mc:Ignorable="d" 
               d:DesignHeight="450" d:DesignWidth="800"&gt;
      &lt;Grid Background="#FF2C2929"&gt;
          &lt;DataGrid  DataGridCell.Selected="DataGrid_GotFocus" SelectionUnit="Cell" 
                     SelectionMode="Single" Name="Datagrid"  AutoGenerateColumns="False" 
                     PreviewKeyDown="Datagrid_PreviewKeyDown" 
                     CurrentCellChanged="Datagrid_CurrentCellChanged"&gt;
  
              &lt;DataGrid.Columns&gt;
  
                  &lt;DataGridTextColumn Header="Code" Width="1*" Binding="{Binding Code}"/&gt;
                  &lt;DataGridTextColumn Header="Code" Width="1*" Binding="{Binding Name}"/&gt;
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>and on Constructor i've write code.</p>
  
  <pre><code>public FileTab()
  {
      InitializeComponent();
  
      AddValues();
  
  
      var grid = Datagrid;
      var cell = new DataGridCellInfo(0, grid.Columns[0]);
      grid.CurrentCell = cell;
      Dispatcher.BeginInvoke(new Action(() =&gt;
      {
          grid.BeginEdit();
      }), System.Windows.Threading.DispatcherPriority.Background);
  
  }
  </code></pre>