title: Unable to cast object of type 'System.Windows.Controls.Grid' to type 'System.Windows.Controls.TabItem'
body: <p>Hi there i have define more than one tabItem in my TabControl. tabItem1, tabItem2, tabItem3</p>
  
  <p>these are CloseableTabItem.</p>
  
  <p>if i add a node in tabItem1 and press a button to make a subGraph model for this node. the </p>
  
  <p>same node should be appear in tabItem2 so that tabItem2-Header = nodeName and nodeName = </p>
  
  <p>tabItem1-Header.</p>
  
  <p>Without (TabItem)tabControl.SelectedContent == tabItem1, the code work correct but the</p>
  
  <p>Problem ist if i added a new node in tabItem2 and press the subGraph-Button node will be </p>
  
  <p>added to tabItem3 but the nodeName = tabItem1-Header.</p>
  
  <p>my Code throw an Exception "Unable to cast object of type 'System.Windows.Controls.Grid' to type 'System.Windows.Controls.TabItem'."</p>
  
  <pre><code>MyNodeData todata = new MyNodeData();
  if (tabItem1.IsLoaded &amp;&amp; (TabItem)tabControl.SelectedContent == tabItem1)
  {
    string childNodeName = (String)tabItem1.Header;
    todata.Text = childNodeName;
    return;
  }
   if (tabItem2.IsLoaded)
  {
    string childNodeName = (String)tabItem2.Header;
    todata.Text = childNodeName;
    return;
  }
   if (tabItem3.IsLoaded)
  {
    string childNodeName = (String)tabItem3.Header;
    todata.Text = childNodeName;
    return;
  }
  </code></pre>