This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Windows Presentation Foundation
.NET 4.0+

WPF Layout Controls - TabControl

The sixteenth part of the Windows Presentation Foundation Fundamentals tutorial continues the examination of the most common layout controls. This instalment covers the TabControl, which allows pages of controls to be shown in a single area.

Selecting the Initial Tab

If you want a different tab to be selected when the TabControl is first shown, you can select it using a property of the desired TabItem. Simply set the Boolean IsSelected value to true, either within the XAML or from code. To demonstrate, change the Salary TabItem's opening tag to the following XAML and re-run the program. You should see that the Salary tab is open when the window loads.

<TabItem Header="Salary" IsSelected="True">

Changing the Tab Strip Position

The tab strip does need not be placed at the top of a TabControl. If you want to recreate interfaces such as those used in Visual Studio, you can dock the tab strip at the bottom of the control. You can also place it at either the left or right edge, in which case the tabs will be stacked vertically. To change the position, set the TabStripPlacement property to Left, Right, Top or Bottom. From code the property must be set to a value from the Dock enumeration in the System.Windows.Controls namespace.

Try modifying the TabControl's opening XAML tag as follows:

<TabControl Margin="5 5 5 0" TabStripPlacement="Bottom">

This moves the tab strip to beneath the TabControl's content, as shown below:

WPF Tab Control with Bottom TabStripPlacement

5 June 2013