Private void btnSelectedTab_Click(object sender, RoutedEventArgs e) Int newIndex = tcSample.SelectedIndex - 1 Private void btnPreviousTab_Click(object sender, RoutedEventArgs e) Public partial class ControllingTheTabControlSample : Window Namespace WpfTutorialSamples.Misc_controls In the next example, I've added a couple of buttons to the firstĮxample which allows us to control the TabControl: Several properties which makes this possible, including SelectedIndex and SelectedItem. Sometimes you may wish to control which tab is selected programmatically or perhaps get some information about the selected tab. The tabs as well as customize the color of the text (we could have made it bold, italic or another size as well). This allows us to have an image on each of TabControl.Header element, which contains a StackPanel, which in turn contains an Image and a TextBlock control. The amount of markup might be a bit overwhelming, but as you can probably see once you dig into it, it's all very simple. It, but so can the tab headers! The Header property can be filled with anything you like, which we'll take advantage of in the next example: Obviously the content can be rendered any way you like Once again, WPF proves to be extremely flexible when you want to customize the look of your tabs. The panels with child controls inside of it. I used a Label in this example, but if you want to place more than one control inside of the tab, just use one of The TabItem element comes from the ContentControl class, which means that you may define a single element inside of it that will be shown if the
Here's a very basic example: Īs you can see, each tab is represented with a TabItem element, where the text shown on it is controlled by the Header Just like with most other WPF controls, the TabControl is very easy to get started with.
Tab controls are commonly used in Windows applications and even within Windows' own interfaces, like the properties dialog for The WPF TabControl allows you to split your interface up into different areas, each accessible by clicking on the tab header, usually positioned at the top