title: How can I determine where the Focus is *right now*?
body: <h2>The short version</h2>
  
  <pre><code>public class CustomDataGrid : DataGridControl, IXmlSettingsProvider
  {
      public CustomDataGrid()
      {
          if (DesignModeHelper.IsInDesignMode) return;
  
          Loaded += (e, a) =&gt;
                        {
                            ...
                        };
  
          LostFocus += (e, a) =&gt;
                           {
                               if(IsBeingEdited /* &amp;&amp;
                                  CurrentFocusTarget.GetType() == typeof(TabControl)*/)
                                  EndEdit();
                           };
      }
  }
  </code></pre>
  
  <p>How can I find <code>UIElement CurrentFocusTarget</code> in the above sample?</p>
  
  <h2>The long version - Context</h2>
  
  <p>We use the XCeed DataGrid in order to show data in different tabs of a lazy-loaded TabControl. Each tab is lazy-loaded so that the content gets rendered (and, more importantly, the data is fetch) only when the tab is Visible. The whole data flow works great using the MVVM approach.</p>
  
  <h2>The problem</h2>
  
  <p>Somehow, whenever the user makes changes to a cell and <strong>Changes Tab</strong>, the databound ViewModel property (that had already been updated) is being set to <code>null</code>.</p>
  
  <p>In order to avoid this, it is possible to call EndEdit() when the focus is lost from the grid.</p>
  
  <p>However, I only want to call it when the focus is lost to a TabItem (or the TabControl).</p>
  
  <p>So, my question is:</p>
  
  <p><strong>What is the easiest way to know where the <code>Focus</code> is <em>right now</em></strong>, from the codebehind. I have inspected the <code>FocusManager</code> but can't seem to find the current Focus bearer (or to whom the focus is lost).</p>