TabItem
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 | |
|---|---|
IsAnimationEnabledOnMouseEnter | Gets or sets whether this tab briefly swells when the pointer moves onto it. |
IsCloseButtonVisible | Gets or sets whether this tab shows its close button, and so whether the user can ask to close it. |
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. |
| Methods | |
OnApplyTemplate | Connects the close button in the tab's template, and shows or hides it according to
IsCloseButtonVisible. |
OnMouseUp | Asks for the tab to be closed when the user middle-clicks it, as a browser's tabs do. |
| Events | |
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. |
| Fields | |
CloseTabItemClickEvent | Identifies the CloseTabItemClick routed event. |
IsAnimationEnabledOnMouseEnterProperty | Identifies the IsAnimationEnabledOnMouseEnter dependency property. |
IsCloseButtonVisibleProperty | Identifies the IsCloseButtonVisible dependency property. |
IsDimmedStateEnabledForUnSelectedItemsProperty | Identifies the IsDimmedStateEnabledForUnSelectedItems dependency property. |
Properties
IsAnimationEnabledOnMouseEnter
Gets or sets whether this tab briefly swells when the pointer moves onto it.
- Value
trueto animate. The default isfalse.
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
Gets or sets whether this tab shows its close button, and so whether the user can ask to close it.
- Value
trueto show the close button. The default istrue.
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
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
trueto fade the tab to 30% opacity. The default isfalse.
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
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
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
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
Identifies the CloseTabItemClick routed event.
IsAnimationEnabledOnMouseEnterProperty static
Identifies the IsAnimationEnabledOnMouseEnter dependency property.
IsCloseButtonVisibleProperty static
Identifies the IsCloseButtonVisible dependency property.
IsDimmedStateEnabledForUnSelectedItemsProperty static
Identifies the IsDimmedStateEnabledForUnSelectedItems dependency property.