【发布时间】:2011-01-28 05:15:21
【问题描述】:
我想拥有自己的基本 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 标记,则错误表示无法定义不同的基类。
如何解决这个问题?
【问题讨论】:
标签: c# wpf user-controls controls wpf-controls