title: Determine who has focus in WPF Window
body: <p>We are using WPF and have a window derived from a DockingLibrary. This window has a grid with multiple items in it, one being a WPF datagrid. We are using the M-V-VM pattern. When this windown is created and shown, none of the rows in this datagrid are selected. We can set the row to display as highlighted by doing something like:</p>
  
  <pre><code>  SharedWindow.ShipmentWin.shipmentDataGrid.SelectedIndex = 0;
  </code></pre>
  
  <p>This causes the first row in the datagrid to be shown as highlighted. But, and isn't there always one of these, this row is not Selected nor does it have Focus. I tried setting IsSelected and Focus on this row as in:</p>
  
  <pre><code>  SharedWindow.ShipmentWin.ShipVM.IsSelected = true;
    bool focused = SharedWindow.ShipmentWin.shipmentDataGrid.Focus();
  </code></pre>
  
  <p>Am I going about this all wrong and is there some other way to Select the first row in the datagrid and set focus to it? Typically, when a datagrid is created, no row is selected until the user mouse clicks on the desired row.</p>
  
  <p>Any thoughts would be greatly appreciated.</p>
  
  <p>thanks!</p>