How to add custom-control-derived TabItem to TabControl in WPF?

Posted by orloffm on Stack Overflow See other posts from Stack Overflow or by orloffm
Published on 2010-03-16T16:49:21Z Indexed on 2010/03/16 16:51 UTC
Read the original article Hit count: 478

Filed under:
|
|
|
|

I want to have my own base TabItem class and use other classes that derive from it.

I define base class in MyNs namespace like this:

public class MyCustomTab : TabItem
{
    static MyCustomTab()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(MyCustomTab), new  FrameworkPropertyMetadata(typeof(TabItem)));
    }
}

And this is what I do for the class that inherits from it:

code-behind in MyNs namespace:

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>

The error I get is "The tag 'MyCustomTab' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'". If I use TabItem tag in XAML the error says that it's not possible to define to different base classes.

How to fix this?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#