title: WPF C# Programmatically adding and moving tabs
body: <p>I'm currently working on something that is probably done in plenty of examples out there. But after some searching I can't find anything.</p>
  
  <p>I'm working with WPF tab control and I'm trying to recreate some basic functionality (which you see in all internet browsers nowadays) to add a new tab by clicking a '+' tab which is the last listed tab.</p>
  
  <p>I already have the '+' tab which adds a new tab. My problem is, I want to move the '+' tab after the new tab (so its the end tab again) and switch view to the new tab that has just been created.</p>
  
  <p>I thought something like:</p>
  
  <pre><code>    void tiNewTab_Add(object sender, EventArgs e)
      {
          int idx = tabControl1.Items.Count;
          tabControl1.SelectedIndex = idx - 1;
          TabItem ti = new TabItemKPI();
          tabControl1.Items.Add(ti);
          tabControl1.Items.MoveCurrentToLast();
      }
  </code></pre>
  
  <p>...would work but no luck :(</p>