title: How to change the order of the TabItem in the wpf TabControl
body: <p>I need to change the order of the TabItem.</p>
  
  <p>I've tried with Remove / Insert and it doesn't works.</p>
  
  <pre><code>void UserControl_Loaded(object sender, RoutedEventArgs e) {
    if(condition) {
      TabControl.Items.Remove(TabItem);
        TabControl.Items.Insert(0, TabItem);
      }
  }
  </code></pre>
  
  <p>InvalidOperationException:
  Element already has a logical parent. It must be detached from the old parent before it is attached to a new one.</p>
  
  <p>How to solve this?</p>