我希望拥有自己的基础TabItem类,并使用从它派生的其他类。
我在MyNs命名空间中定义了基类,如下所示:
public class MyCustomTab : TabItem
{
static MyCustomTab()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyCustomTab), new FrameworkPropertyMetadata(typeof(TabItem)));
}
}
以下是我为继承它的类所做的操作:
在MyNs命名空间中的代码后台:
public partial class ActualTab : MyCustomTab
{
public ActualTab()
{
InitializeComponent();
}
}
XAML:
<MyCustomTab x:Class="MyNs.ActualTab"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
</Grid>
</MyCustomTab>
我得到的错误信息是:“在 XML 命名空间 'http://schemas.microsoft.com/winfx/2006/xaml/presentation' 中不存在“'MyCustomTab'”标记。如果我在 XAML 中使用
TabItem
标签,该错误会指出不可能定义两个不同的基类。
如何解决这个问题?