views:

628

answers:

3

Hi, I'm looking to create a new control template for a WPF tabcontrol.

The situation I have is that there will be a number of tabs in the control and the user will be able to add and delete these tabs.

Ideally I would like to create something along the lines of the Firefox / IE tabs whereby you have a delete button inside the tab heading to delete the current tab.

Also, and slightly more complicated, I want to have a new tab button that is always on the right hand side of the last tab in the tabcontrol.

Could anyone point me in a direction to get started? I've seen examples of people using Blend for this to create the new template. So far I've not been using that but have just downloaded the trial...

Thanks.

+1  A: 

In this article (referred to MVVM) the author make use of control templates to style the tabs, with close button et al.

alt text

Or you can go more basic with this sample

alt text

Eduardo Molteni
+1  A: 

The "new tab" button is more complicated. The main issue is that you want it to show up at the correct place in the ItemsPresenter/TabPanel but it isn't part of the collection driving the ItemsPresenter because it isn't actually a TabItem. I've done this in the past by modifying the ControlTemplate of the TabControl itself to stick the button onto the right side of the ItemsPresenter but you can end up with a weird look in situations where the tabs bump into a second row since the button isn't part of the TabPanel's layout.

John Bowen
A: 

How about using a TemplateSelector ?

Create two different templates - one for your normal tab items and one for your "new tab button". Both are actually tab items but with different templates depending on the conditions in your TemplateSelector.

To achieve different behavior / identify your "new tab button" just check in your code which template is assigned.

Hope that helps a bit.

banzai