Click here to Skip to main content
15,113,131 members
Articles / Desktop Programming / WPF
Posted 13 Oct 2007


151 bookmarked

An Extended WPF TabControl

Rate me:
Please Sign up or sign in to vote.
4.78/5 (58 votes)
5 Apr 2009CPOL3 min read
Altering the WPF TabControl to show a single row of scrolling TabItems
Screenshot - TabControl_Default.jpg


I recently decided to have a go at changing the built-in WPF TabControl so that it behaves similar to the way in which Internet Explorer 7 works.

The main area I wanted to change was the way in which the TabItems are arranged, currently the built-in TabControl will pack and stack items, so the more items there are, the more room is required for the headers, taking up space from the actual content of the TabItem.

With Internet Explorer 7, tabs remain on a single row and will scroll in and out of view. This is the way I wanted this control to behave.


There are a few extra properties (Dependency Properties) and events added to the control.

  • AllowAddNew - Setting this property to true will allow the end user to add new tabitems to the control via a button.
  • AllowDelete - Setting this property to true will allow the end user to delete tabitems from the control by clicking on the close button on the selected tabitem.

If the above properties are set to true, there are three events that go with these properties. They are TabItemAdded, TabItemClosing and TabItemClosed: all provide a reference to the TabItem being added/removed, the TabItemClosing event providing a place to cancel the close if required.

  • AddNewTabToEnd - If this property is true, tabitems added using the AddNew button will be added to the end of the row of tabitems, otherwise the new tabitem will be inserted immediately after the current selection.
  • SelectNewTabOnCreate - If this property is true, focus will be moved to the new tabitem when added.

Finally, there are three extra properties of type Brush which are used for coloring the tabitems based on their state:

  • TabItemNormalBackground
  • TabItemMouseOverBackground
  • TabItemSelectedBackground

If you look at the picture at the top of this article, it shows the default style for the TabControl. I've intentionally made this very basic. By just using the extra Background properties, you can easily change the appearance of the TabControl. As this picture shows, by adding a few LinearGradientBrushes, you can get something that resembles Internet Explorer 7.


There are four properties which take an active part in the arrangement of the tabitems. They are:

  • TabItemMinWidth
  • TabItemMaxWidth
  • TabItemMinHeight
  • TabItemMaxHeight

Arranging the TabItems

There are three ways in which the tabcontrol arranges its tabitems.
The following description is relevant if the TabStripPlacement property is set to Top or Bottom.

  1. If the combined widths of the TabItems is less than the available visible space, then we just arrange them one after the other, taking into account the TabItemMaxWidth and TabItemMinWidth properties.
  2. If the combined widths are greater than visible, then calculate the width required for all the tabitems so that all are visible. If this width is greater than the TabItemMinWidth property, then we arrange the tabitems using this calculated width.
  3. Once we add too many tabitems that their widths would be less than the TabitemMinWidth property, then scrolling will be enabled.

The class that is responsible for arranging the tabitems is the VirtualizingTabPanel. As the name suggests, this panel derives from the VirtualizingPanel class and implements the IScrollInfo interface. I won't describe here what a VirtualizingPanel is, instead I will just direct you to this Blog post by Dan Crevier which describes what it is and how to implement one.

Using the Code

To use the control, you will need to add a reference to the Wpf.TabControl assembly, then add an xmlns to the window:


The demo provided shows how to add the control to a window and set its properties.


  • 13-Oct-2007: Initial upload
  • 09-Mar-2009: Implemented ItemsSource binding & bug fixes
  • 05-Apr-2009: Updated source code


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

QuestionFix the no of tabs in the tabcontrol Pin
najmbe13-Jul-14 22:04
Membernajmbe13-Jul-14 22:04 
QuestionHow can I integrate this into the Prism technology? Pin
VcDevelopment28-May-13 16:38
MemberVcDevelopment28-May-13 16:38 
GeneralMy vote of 4 Pin
vanwood26-Feb-13 3:05
Membervanwood26-Feb-13 3:05 
GeneralMy vote of 5 Pin
hari111r28-Nov-12 18:55
Memberhari111r28-Nov-12 18:55 
QuestionFirst Tab isfixed Pin
Patrick Blackman20-Jun-12 18:14
professionalPatrick Blackman20-Jun-12 18:14 
QuestionHow I can use this Tab control in WinApp projects? Pin
ctrlz-jc13-May-12 19:19
Memberctrlz-jc13-May-12 19:19 
GeneralMy vote of 5 Pin
Steve Aube 126-Dec-11 12:24
MemberSteve Aube 126-Dec-11 12:24 
GeneralMy vote of 5 Pin
Kashif_Imran11-Dec-11 1:31
MemberKashif_Imran11-Dec-11 1:31 
GeneralMy vote id 5 Pin
edallos22-Mar-11 1:46
professionaledallos22-Mar-11 1:46 
GeneralMy vote of 5 Pin
Slacker0078-Dec-10 8:24
professionalSlacker0078-Dec-10 8:24 
GeneralModifying tab control to show the selected tabs header in bold [modified] Pin
ACanadian17-Sep-10 10:24
MemberACanadian17-Sep-10 10:24 
GeneralMy vote of 4 Pin
Steven Chen11-Aug-10 7:03
MemberSteven Chen11-Aug-10 7:03 
GeneralMy vote of 5 Pin
zokbari2-Aug-10 8:46
Memberzokbari2-Aug-10 8:46 
QuestionWhat controls the default xaml when first dropped onto designer? Pin
pattyweb23-Jun-10 17:53
Memberpattyweb23-Jun-10 17:53 
GeneralProperties TabItemNormalBackground, TabItemMouseOverBackground, TabItemSelectedBackground for each TabItem Pin
jiglriv10-May-10 0:42
Memberjiglriv10-May-10 0:42 
GeneralIsFixedSize property question Pin
Member 45553309-May-10 5:22
MemberMember 45553309-May-10 5:22 
QuestionThank you and a question Pin
msabatini28-Apr-10 7:29
Membermsabatini28-Apr-10 7:29 
AnswerRe: Thank you and a question Pin
cupitor15-Sep-17 4:42
Membercupitor15-Sep-17 4:42 
GeneralRe: Thank you and a question Pin
msabatini10-Jan-20 6:18
Membermsabatini10-Jan-20 6:18 
QuestionWhat a good article Pin
superdiablo18-Apr-10 7:17
Membersuperdiablo18-Apr-10 7:17 
GeneralThank you and new functionality implemented Pin
Evgeny Vinnik2-Jul-09 19:09
MemberEvgeny Vinnik2-Jul-09 19:09 
GeneralRe: Thank you and new functionality implemented Pin
Jose Maldonado5-Jan-10 6:38
MemberJose Maldonado5-Jan-10 6:38 
GeneralRe: Thank you and new functionality implemented Pin
robyg721118-Nov-10 4:30
Memberrobyg721118-Nov-10 4:30 
GeneralBug: RepeatRight and RepeatLeft buttons do not display in WindowUsingItemsSourceProperty.xaml Pin
Rolenun24-May-09 19:27
MemberRolenun24-May-09 19:27 
General[My vote of 2] need code snippets and discussion Pin
Donsw16-Apr-09 7:44
MemberDonsw16-Apr-09 7:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.