Closeable TabItem

Jul 25, 2008 at 6:27 AM
Edited Jul 25, 2008 at 6:31 AM
Can anyone explain how the SelectorRegionAdapter when used in a TabControl identifies a TabItem as the type for any child control.

And how this might be intercepted.

I'm trying to have the TabControl use a CloseableTabItem instead as per the appraoch outlined here

Jul 25, 2008 at 10:02 AM
The solution is quite simple. You can combine the closable tabitem sample with a sample I created earlier:

CompositeWPF supports using the TabControl as a region quite nicely, so this shouldn't be much of a problem.
Jul 29, 2008 at 12:51 AM
Thanks for the suggestion. However the TabControl wants to instantiate a TabItem rather than a CloseableTabItem.

Looking through your sample, this seems to represent an alternative approach that is not so easily combined.

What I'm looking for is a place where I can specify that the TabControl container should have as its items a set fo controls of the type CloseableTabItem. 
Jul 30, 2008 at 12:37 PM
To get the functionality you require I recommend creating a custom version of the tabcontrol and inherit from the original tabcontrol.
The following piece of code can help in the process:

public class ClosableTabControl: TabControl
    protected override DependencyObject GetContainerForItemOverride()
        return new ClosableTabItem();

    protected override bool IsItemItsOwnContainerOverride(Object item)
        return item is ClosableTabItem;

public class ClosableTabItem: TabItem

Jul 31, 2008 at 7:46 AM
Thanks - With bit of fiddling that worked.
Aug 5, 2008 at 7:52 AM
Edited Aug 5, 2008 at 7:53 AM
You don't need to wrap the original tabcontrol to get closable tabitems. I needed the same trick for different application so I created a couple of custom templates and a small piece of code. I even wrote a blogpost about it so others could use that trick as well :