[英]How to add custom-control-derived TabItem to TabControl in WPF?
我想拥有自己的基类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>
我得到的错误是“标签'MyCustomTab'在XML名称空间' http://schemas.microsoft.com/winfx/2006/xaml/presentation '中不存在。” 如果我在XAML中使用TabItem
标记,则错误表明无法定义到不同的基类。
如何解决这个问题?
好吧,我很蠢,应该是
<MyNs:MyCustomTab x:Class="MyNs.ActualTab"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:MyNs="clr-namespace:MyNs">
<Grid>
</Grid>
</MyNs:MyCustomTab>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.