HypernovaDesktop Components · docs
Binarymission
WPF › Tab Control › TabItem

TabItem

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Controls.Containers

A tab of the TabControl, with a close button, drawn in the tab control's TabControl.RenderingMode.

public class TabItem : System.Windows.Controls.TabItem

Inherits from / implements: System.Windows.Controls.TabItem

Remarks

Add these, rather than WPF's own tab items, to a TabControl: the tab styles, the colours and the close button apply to them. Set HeaderedContentControl.Header to the tab's title and ContentControl.Content to its page, as for any tab.

The close button, a middle click on the header and Ctrl+F4 while the tab is selected all raise CloseTabItemClick; the tab is removed only if the application's handler removes it. IsCloseButtonVisible makes a tab that cannot be closed.

Examples

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

TabItem invoice = new TabItem
{
    Header = "Invoice 10482",
    Content = new InvoiceView(10482),
    IsAnimationEnabledOnMouseEnter = true
};
invoice.CloseTabItemClick += (sender, e) => documents.Items.Remove(invoice);
documents.Items.Add(invoice);

See also

Members at a glance

Properties
IsAnimationEnabledOnMouseEnterGets or sets whether this tab briefly swells when the pointer moves onto it.
IsCloseButtonVisibleGets or sets whether this tab shows its close button, and so whether the user can ask to close it.
IsDimmedStateEnabledForUnSelectedItemsGets or sets whether this tab is faded while it is neither selected nor under the pointer, so that the selected tab stands out.
Methods
OnApplyTemplateConnects the close button in the tab's template, and shows or hides it according to IsCloseButtonVisible.
OnMouseUpAsks for the tab to be closed when the user middle-clicks it, as a browser's tabs do.
Events
CloseTabItemClickOccurs when the user asks to close this tab: with its close button, a middle click on its header, or Ctrl+F4 while it is selected.
Fields
CloseTabItemClickEventIdentifies the CloseTabItemClick routed event.
IsAnimationEnabledOnMouseEnterPropertyIdentifies the IsAnimationEnabledOnMouseEnter dependency property.
IsCloseButtonVisiblePropertyIdentifies the IsCloseButtonVisible dependency property.
IsDimmedStateEnabledForUnSelectedItemsPropertyIdentifies the IsDimmedStateEnabledForUnSelectedItems dependency property.

Properties

IsAnimationEnabledOnMouseEnter

public bool IsAnimationEnabledOnMouseEnter

Gets or sets whether this tab briefly swells when the pointer moves onto it.

Value
true to animate. The default is false.
Remarks

The tab grows to 135% of its width and 120% of its height and settles back over 0.3 seconds – a playful cue suited to a touch screen or a launcher, less so to a document window.

IsCloseButtonVisible

public bool IsCloseButtonVisible

Gets or sets whether this tab shows its close button, and so whether the user can ask to close it.

Value
true to show the close button. The default is true.
Remarks

With the button hidden, a middle click on the tab and Ctrl+F4 do not ask for it to be closed either – use it for tabs that must always be there, such as a start page or a summary. A disabled tab cannot be closed by the user either.

Example
<tabs:TabItem Header="Dashboard" IsCloseButtonVisible="False" />
See also

IsDimmedStateEnabledForUnSelectedItems

public bool IsDimmedStateEnabledForUnSelectedItems

Gets or sets whether this tab is faded while it is neither selected nor under the pointer, so that the selected tab stands out.

Value
true to fade the tab to 30% opacity. The default is false.
Remarks

The tab returns to full strength under the pointer and when selected. It has no effect in the TabControlRenderingMode.VisualStudio mode. Set it on every tab, through an ItemsControl.ItemContainerStyle or a style for TabItem, for an even effect.

Methods

OnApplyTemplate

public override void OnApplyTemplate()

Connects the close button in the tab's template, and shows or hides it according to IsCloseButtonVisible.

Remarks

A custom template names its close button PART_TabItemCloseButton. A template without one gives a tab that the user cannot close by middle click or Ctrl+F4 either.

OnMouseUp

protected override void OnMouseUp(MouseButtonEventArgs e)

Asks for the tab to be closed when the user middle-clicks it, as a browser's tabs do.

Parameters
e
The mouse button released.
Remarks

Only while the tab is enabled and has a visible close button; the request raises CloseTabItemClick.

Events

CloseTabItemClick

public event RoutedEventHandler CloseTabItemClick

Occurs when the user asks to close this tab: with its close button, a middle click on its header, or Ctrl+F4 while it is selected.

Remarks

The tab is not removed unless a handler removes it, which leaves room to ask about unsaved changes first, or to refuse. The event's source is the tab.

It bubbles, so one handler on the TabControl – in XAML, tabs:TabItem.CloseTabItemClick="OnCloseTab" – serves every tab; read the tab from RoutedEventArgs.OriginalSource.

Example
documents.AddHandler(TabItem.CloseTabItemClickEvent, new RoutedEventHandler((sender, e) =>
{
    TabItem tab = (TabItem)e.OriginalSource;
    if (!(tab.Content is IDocument doc) || doc.ConfirmClose())
    {
        documents.Items.Remove(tab);
    }
}));
See also

Fields

CloseTabItemClickEvent static

public static readonly RoutedEvent CloseTabItemClickEvent

Identifies the CloseTabItemClick routed event.

IsAnimationEnabledOnMouseEnterProperty static

public static readonly DependencyProperty IsAnimationEnabledOnMouseEnterProperty

Identifies the IsAnimationEnabledOnMouseEnter dependency property.

IsCloseButtonVisibleProperty static

public static readonly DependencyProperty IsCloseButtonVisibleProperty

Identifies the IsCloseButtonVisible dependency property.

IsDimmedStateEnabledForUnSelectedItemsProperty static

public static readonly DependencyProperty IsDimmedStateEnabledForUnSelectedItemsProperty

Identifies the IsDimmedStateEnabledForUnSelectedItems dependency property.