我创建了一个名为SmartTabItem的自定义控件,目前只有默认实现:
using System.Windows;
using System.Windows.Controls;
namespace TestControl.Controls
{
public class SmartTabItem : TabItem
{
static SmartTabItem()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(SmartTabItem), new FrameworkPropertyMetadata(typeof(SmartTabItem)));
}
}
}
我将它包含在我的TabControl中,方法如下:
<Window x:Class="TestControl.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:TestControl.Controls"
Title="Window1" Height="300" Width="300">
<DockPanel Margin="10">
<TabControl>
<controls:SmartTabItem Header="One">content of one</controls:SmartTabItem>
<TabItem Header="Two">content of two</TabItem>
<TabItem Header="Three">content of three</TabItem>
</TabControl>
</DockPanel>
</Window>
但是只有“Two”和“Three”这两个选项卡被显示出来了。如果SmartTabItem继承自TabItem,为什么它没有出现在TabControl中呢?