WPF C# Programmatically adding and moving tabs

前端 未结 2 1409
夕颜
夕颜 2021-01-04 13:09

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.

I\'m working with WPF tab

相关标签:
2条回答
  • 2021-01-04 13:45

    Not tested, but following should work:

    int idx = tabControl1.Items.Count;
    tabControl1.SelectedIndex = idx - 1;
    TabItem ti = new TabItem();
    tabControl1.Items.Insert(tabControl1.Items.IndexOf(tabControl1.Items.Last()), ti);
    
    0 讨论(0)
  • 2021-01-04 13:53

    Try something like this:

    tabControl1.Items.Insert(tabControl1.Items.Count-1,ti); 
    

    This will do because you always have at least one TabItem (the + one)

    Then select the second last one by

    tabControl1.SelectedIndex=tabControl1.Items.Count-2;
    
    0 讨论(0)
提交回复
热议问题