HypernovaDesktop Components · docs
Binarymission
WPF › Tab Control

Tab Control

.NET Framework 4.8.NET 6 / 8 / 10v4.0.0WPF

A tab control with sixteen built-in tab styles, closable tabs, an add-new-tab button, a strip that scrolls when the tabs overflow, and every colour open to change – for document windows, browsers, editors and settings pages.

4public types
102public members
2namespaces

Assembly

AssemblyBinarymission.WPF.Controls.TabControl.dll
Root namespaceBinarymission.WPF.Controls.Containers
Target frameworks.NET Framework 4.8, .NET 6 / 8 / 10
Depends onSkinning

Overview

It is a TabControl, so selection, keyboard navigation, TabStripPlacement (top, bottom, left or right) and SelectionChanged all work as usual. Fill it with this assembly's TabItem, which adds the close button; the tab styles and colours apply to those tabs.

Look

RenderingMode chooses the tab style – the classic shaped tabs (TabControlRenderingMode.Default, TabControlRenderingMode.Trapezium, TabControlRenderingMode.Diamond ...) or the flatter modern ones (TabControlRenderingMode.Browser, TabControlRenderingMode.Fluent, TabControlRenderingMode.Underline ...) – and can be changed at any time without moving the selection. With TabControlRenderingMode.Custom, draw the tabs with a template of your own in TabItemControlTemplate.

Every colour has a property: the page (TabControlBackground), the tabs (TabItemPathBrush, TabItemSelectedFill, TabItemTextForeground), the accent of the modern modes (TabItemAccentBrush), the strip, the scroll buttons and the close buttons. The defaults come from the keys in SharedResources.TabControlResources: with no Binarymission skin in force they are the control's own warm orange and gold scheme, and with a skin they follow the skin. A brush set on the control wins over both.

Opening and closing tabs

The control never adds or removes tabs itself, so the application stays in charge of its documents. IsAddNewTabItemButtonVisible shows a "+" button at the end of the strip that raises AddNewTabItemClick. A tab's close button, a middle click on its header and Ctrl+F4 on the selected tab raise TabItem.CloseTabItemClick, where the application can ask to save changes and then remove the tab.

Many tabs

When the tabs do not fit, the strip scrolls, with a pair of arrow buttons at its end to move along it.

Getting started

A document window with browser-style tabs, an add button, and tabs that close when asked.

<Window x:Class="Notes.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:tabs="clr-namespace:Binarymission.WPF.Controls.Containers;assembly=Binarymission.WPF.Controls.TabControl"
        Title="Notes" Width="900" Height="600">

    <tabs:TabControl x:Name="Documents"
                     RenderingMode="Browser"
                     TabStripBackground="#E8EBEF"
                     TabControlBackground="White"
                     IsAddNewTabItemButtonVisible="True"
                     AddNewTabItemTooltipText="New note"
                     CloseTabTooltipText="Close note"
                     AddNewTabItemClick="OnAddNote"
                     tabs:TabItem.CloseTabItemClick="OnCloseNote">
        <tabs:TabItem Header="Welcome" IsCloseButtonVisible="False">
            <TextBlock Margin="16" Text="Press + to start a new note." />
        </tabs:TabItem>
        <tabs:TabItem Header="Meeting notes">
            <TextBox AcceptsReturn="True" />
        </tabs:TabItem>
    </tabs:TabControl>
</Window>

The handlers that add and remove the tabs.

using System.Windows;
using System.Windows.Controls;
using Binarymission.WPF.Controls.Containers;
using TabItem = Binarymission.WPF.Controls.Containers.TabItem;

private int _untitled = 1;

private void OnAddNote(object sender, RoutedEventArgs e)
{
    TabItem note = new TabItem
    {
        Header = "Untitled " + _untitled++,
        Content = new TextBox { AcceptsReturn = true }
    };
    Documents.Items.Add(note);
    Documents.SelectedItem = note;
}

private void OnCloseNote(object sender, RoutedEventArgs e)
{
    TabItem note = (TabItem)e.OriginalSource;
    if (MessageBox.Show("Close " + note.Header + "?", "Notes", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
    {
        Documents.Items.Remove(note);
    }
}

API reference

Binarymission.WPF.Controls.Containers

class TabControlA tab control with sixteen built-in tab styles, closable tabs, an add-new-tab button, a strip that scrolls when the tabs overflow, and every colour open to change - for document windows, browsers, editors and settings pages.
enum TabControlRenderingModeThe built-in shapes and styles a TabControl can draw its tabs in.
class TabItemA tab of the TabControl, with a close button, drawn in the tab control's RenderingMode.

Binarymission.WPF.Controls.Containers.SharedResources

class TabControlResourcesThe resource keys of the colours TabControl is drawn with, one for each of its brush properties, so that an application can restyle every tab control at once from its own resources.