【问题标题】:How to change the order of the TabItem in the wpf TabControl如何更改 wpf TabControl 中 TabItem 的顺序
【发布时间】:2010-11-02 23:36:58
【问题描述】:

我需要更改 TabItem 的顺序。

我尝试过删除/插入,但它不起作用。

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

无效操作异常: 元素已经有一个逻辑父级。在附加到新的父级之前,它必须与旧父级分离。

如何解决?

【问题讨论】:

  • 上面列出的代码在常规窗口中对我有用(我没有尝试使用 UserControl)。我假设 TabItem 是实际 TabItem 的名称,而不仅仅是 TabItem 关键字?

标签: wpf tabcontrol tabitem


【解决方案1】:

使用“for”而不是“foreach”解决。

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

【讨论】:

  • 我正在寻找将我的第二个选项卡设置为在设计视图中选中的选项。我在“属性”窗格中找不到属性 IsSlected,但使用代码完成了它并且它有效。谢谢
  • 能否请您告诉我如何更改 designview (Xaml) (WPF) 中选项卡的顺序,谢谢。
猜你喜欢
  • 2012-11-17
  • 1970-01-01
  • 2018-04-21
  • 2012-09-07
  • 2011-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-30
相关资源
最近更新 更多