如何确定添加到TabControl的项目类型?

时间:2022-09-11 19:26:36

I've created a CloseableTabItem control that derives from TabItem. Now I'd like to specify that a given TabControl should add new items using CloseableTabItem instead of TabItem. Is this possible? How?

我创建了一个从TabItem派生的CloseableTabItem控件。现在我想指定一个给定的TabControl应该使用CloseableTabItem而不是TabItem添加新项目。这可能吗?怎么样?

2 个解决方案

#1


public class CloseableItemsTabControl : TabControl
{
    protected override DependencyObject GetContainerForItemOverride()
    {
        return new CloseableTabItem();
    }
}

#2


You'll probably need to make your own ClosableTabControl that extends TabControl in order to override the base functionality.

您可能需要创建自己的ClosableTabControl来扩展TabControl以覆盖基本功能。

However, you can also probably just add your tabs manually, feeding it your ClosableTabItems instead of regular TabItems. It would be safe to assume this is possible since most collection-based controls are able to be programatically populated this way.

但是,您也可以手动添加选项卡,将其提供给ClosableTabItems而不是常规TabItems。可以安全地假设这是可能的,因为大多数基于集合的控件都能够以这种方式编程填充。

#1


public class CloseableItemsTabControl : TabControl
{
    protected override DependencyObject GetContainerForItemOverride()
    {
        return new CloseableTabItem();
    }
}

#2


You'll probably need to make your own ClosableTabControl that extends TabControl in order to override the base functionality.

您可能需要创建自己的ClosableTabControl来扩展TabControl以覆盖基本功能。

However, you can also probably just add your tabs manually, feeding it your ClosableTabItems instead of regular TabItems. It would be safe to assume this is possible since most collection-based controls are able to be programatically populated this way.

但是,您也可以手动添加选项卡,将其提供给ClosableTabItems而不是常规TabItems。可以安全地假设这是可能的,因为大多数基于集合的控件都能够以这种方式编程填充。