title: Remove tab page from a tab control and display the page as a new Window
body: <p>I am working on a Windows Application using WinForms. I have a tab control(tabMain) and on double clicking the tab page header I need to move its content to a new window and remove the tab from the tabMain.</p>
  
  <p>Here is the code I have tried.</p>
  
  <pre><code> private void tabMain_MouseDoubleClick(object sender, MouseEventArgs e)
      {            
          System.Windows.Controls.TabItem tab = (System.Windows.Controls.TabItem)sender;
          var CurrentTab=tabMain.SelectedTab;            
          if (tabMain.TabPages.Count == 0) return;
          tabMain.TabPages.Remove(tabMain.SelectedTab);   
          System.Windows.Window newWindow=new System.Windows.Window();
          newWindow.Content = tab.Content;
          newWindow.Show();        
      } 
  </code></pre>
  
  <p>On doing this I am getting an error "Unable to cast object of type 'System.Windows.Forms.TabControl' to type 'System.Windows.Controls.TabItem'." for the line :</p>
  
  <pre><code> System.Windows.Controls.TabItem tab = (System.Windows.Controls.TabItem)sender;
  </code></pre>
  
  <p>Is there any fix for this. Or any other possible way out?</p>
  
  <p>Any help would be appreciated</p>
  
  <p>Thanks in advance</p>