开发者

How to change the order of the TabItem in the wpf TabControl

I need to change the order of the TabItem.

I've tried with Remove / Insert and it doesn't works.

void UserControl_Loaded(object sender, RoutedEventArgs e) {
  if(condition) {
    TabControl.Items.Remove(TabItem);
      TabControl.Items.Insert(0, TabItem);
    }
}

InvalidOperationException: Element already has a logical parent. It must be detached from the old parent before it is attached to a new one.

How to solve th开发者_开发问答is?


Solved using the "for" instead of "foreach".

if(condition) {    
  var tabItem = Tab.Items[index];
  Tab.Items.RemoveAt(index);
  Tab.Items.Insert(0, tabItem);
  ((TabItem)tabItem).IsSelected = true;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜