gpt4 book ai didi

c# - 如何将自定义控件派生的 TabItem 添加到 WPF 中的 TabControl?

转载 作者:行者123 更新时间:2023-11-30 18:44:41 25 4
gpt4 key购买 nike

我想拥有自己的 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 标记,错误提示无法定义不同的基类。

如何解决这个问题?

最佳答案

好吧,我傻了,应该是

<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>

关于c# - 如何将自定义控件派生的 TabItem 添加到 WPF 中的 TabControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2456336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com