Click here to Skip to main content
12,299,790 members (56,361 online)
Click here to Skip to main content
Add your own
alternative version


148 bookmarked

An Extended WPF TabControl

, 5 Apr 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
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

You may also be interested in...

Comments and Discussions

GeneralRe: My vote of 2 Pin
r2d2ro17-Jun-11 0:12
memberr2d2ro17-Jun-11 0:12 
GeneralRe: My vote of 2 Pin
John Simmons / outlaw programmer17-Jun-11 2:14
mvpJohn Simmons / outlaw programmer17-Jun-11 2:14 
GeneralCrash while resizing/minimizing window Pin
Member 60381965-Apr-09 1:18
memberMember 60381965-Apr-09 1:18 
GeneralRe: Crash while resizing/minimizing window Pin
alrh5-Apr-09 4:08
memberalrh5-Apr-09 4:08 
GeneralAwesome Pin
nitewulf501-Apr-09 8:32
membernitewulf501-Apr-09 8:32 
GeneralBlink tab item in changes. Pin
Morteza_Ar27-Mar-09 2:26
memberMorteza_Ar27-Mar-09 2:26 
QuestionExtended Silverlight TabControl Pin
Mohammed Issa9-Mar-09 3:59
memberMohammed Issa9-Mar-09 3:59 
Generaldata binding on ItemsSource Pin
Ravejones25-Feb-09 6:22
memberRavejones25-Feb-09 6:22 
GeneralRe: data binding on ItemsSource Pin
alrh11-Mar-09 1:52
memberalrh11-Mar-09 1:52 
Generalmodification: do not virtualize selected tab Pin
chefkokkie14-Feb-09 19:07
memberchefkokkie14-Feb-09 19:07 
GeneralWPF Chrome causes this to not work. Pin
Member 44541963-Feb-09 14:13
memberMember 44541963-Feb-09 14:13 
AnswerRe: WPF Chrome causes this to not work. [modified] Pin
chefkokkie11-Feb-09 20:42
memberchefkokkie11-Feb-09 20:42 
Answernon-uniform width decrease of tabs Pin
chefkokkie3-Feb-09 10:27
memberchefkokkie3-Feb-09 10:27 
AnswerRepeatLEFT and RepeatRIGHT are reversed Pin
chefkokkie2-Feb-09 16:24
memberchefkokkie2-Feb-09 16:24 
GeneralRe: RepeatLEFT and RepeatRIGHT are reversed Pin
Rolenun24-May-09 18:12
memberRolenun24-May-09 18:12 
GeneralWow Pin
Alomgir Miah Abdul26-Dec-08 6:55
memberAlomgir Miah Abdul26-Dec-08 6:55 
GeneralScrollViewer property - VerticalScrollBarVisibility="Auto" error Pin
bluemoong30-Oct-08 4:30
memberbluemoong30-Oct-08 4:30 
GeneralVB Translation Pin
RiccardoG6-Oct-08 5:16
memberRiccardoG6-Oct-08 5:16 
GeneralSet Window1's Height=Auto And Width=Auto ,there is an Error! Pin
anqincmt7-Jul-08 0:31
memberanqincmt7-Jul-08 0:31 
GeneralRe: Set Window1's Height=Auto And Width=Auto ,there is an Error! Pin
jutifruti11-Sep-08 4:57
memberjutifruti11-Sep-08 4:57 
GeneralRe: Set Window1's Height=Auto And Width=Auto ,there is an Error! Pin
Cool Cassis1-Oct-08 1:13
memberCool Cassis1-Oct-08 1:13 
QuestionAutoSize HeaderWidth of TabItem Pin
Horst Klein17-Jun-08 2:26
memberHorst Klein17-Jun-08 2:26 
QuestionCan be used in XBAP apps? Pin
pixel3cs9-May-08 10:17
memberpixel3cs9-May-08 10:17 
Generalimplement data binding feature Pin
Quang Tran Minh16-Apr-08 0:20
memberQuang Tran Minh16-Apr-08 0:20 
GeneralRe: implement data binding feature Pin
icecreman18-Apr-08 4:12
membericecreman18-Apr-08 4:12 
GeneralRe: implement data binding feature Pin
Quang Tran Minh22-Apr-08 2:04
memberQuang Tran Minh22-Apr-08 2:04 
GeneralRe: implement data binding feature Pin
Dividian28-Oct-08 12:32
memberDividian28-Oct-08 12:32 
Generaldatabinding Pin
Quang Tran Minh15-Apr-08 21:42
memberQuang Tran Minh15-Apr-08 21:42 
GeneralDatabinding? [modified] Pin
88Keys10-Dec-07 12:25
member88Keys10-Dec-07 12:25 
GeneralRe: Databinding? Pin
RootSystem19-Jun-08 8:01
memberRootSystem19-Jun-08 8:01 
Generali am trying to add OnAddingNewTab Event Pin
vairam svs5-Dec-07 11:36
membervairam svs5-Dec-07 11:36 
Questionhow did you achieve the X in the part_close Pin
vairam svs5-Dec-07 11:32
membervairam svs5-Dec-07 11:32 
GeneralOpening in 2005 Pin
Psyian25-Nov-07 21:58
memberPsyian25-Nov-07 21:58 
GeneralRe: Opening in 2005 Pin
karak26-Nov-07 5:54
memberkarak26-Nov-07 5:54 
GeneralRe: Opening in 2005 Pin
Psyian26-Nov-07 6:06
memberPsyian26-Nov-07 6:06 
GeneralRe: Opening in 2005 Pin
Psyian26-Nov-07 9:29
memberPsyian26-Nov-07 9:29 
GeneralYes, this looks very intriguing but... [modified] Pin
rikardon9-Nov-07 13:16
memberrikardon9-Nov-07 13:16 
GeneralRe: Yes, this looks very intriguing but... Pin
alrh9-Nov-07 23:29
memberalrh9-Nov-07 23:29 
QuestionVS2008? Pin
disore24-Oct-07 22:25
memberdisore24-Oct-07 22:25 
GeneralRe: VS2008? Pin
Rick Rat2-Feb-08 20:45
memberRick Rat2-Feb-08 20:45 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 5 Apr 2009
Article Copyright 2007 by alrh
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid