Pin and Close
TabControl allows pinning and closing its tab items using built-in buttons that can be optionally displayed in the items.
Pin and Unpin
The pin button of the TabItem is hidden by default. Pin functionality can be enabled by setting the PinButtonVisibility
property of RadTabItem
to Visible
. To check if given tab item is pinned you can use its IsPinned
property.
To get the current pinned tab items you can use the PinnedItems
collection of RadTabControl
. The collection is of type ReadOnlyCollection<RadTabItem>
so no items can be added or removed. You can only use this collection for iteration or to get the current number of the pinned tabs by using its Count
method.
Set the PinButtonVisibility on a single tab
<telerik:RadTabItem PinButtonVisibility="Visible"/>
Set the PinButtonVisibility implicitly to all tab items in the application
<Application.Resources>
<Style TargetType="telerik:RadTabItem" >
<Setter Property="PinButtonVisibility" Value="Visible"/>
</Style>
</Application.Resources>
PinnedItems
collection. If there are 3 pinned items, they will be in indices: 0,1,2. Pinning another item will move it to position 3.
Similar behavior is observed when an item is unpinned. Unpinning an item will move it to the first index possible which is not pinned. For example if items 0 1 2 are pinned. If you unpin 1 it will go to index 2. Unpinning removes the item from the PinnedItems
collection.
The pinned/unpinned item will be brought into the view.
Close
The close button of the TabItem is hidden by default. The button can be shown by setting the CloseButtonVisibility
property of the RadTabItem
to Visible
. Additionally, the TabItem can be closed by pressing the mouse middle button while the mouse is over it.
Set the CloseButtonVisibility on a single tab
<telerik:RadTabItem CloseButtonVisibility="Visible"/>
Set the CloseButtonVisibility implicitly to all tab items in the application
To prevent the tab from closing when the middle mouse button is pressed, set the CloseTabsOnMouseMiddleButtonDown
property of RadTabControl
to false
.
Disable closing the tabs when the middle mouse button is pressed
<telerik:RadTabControl CloseTabsOnMouseMiddleButtonDown="False" />
Events
The TabControl provides several events in regards to its pinning and closing functionalities. Read more in the Events article.
Commands
The TabControl exposes its pinned/unpinned functionality through two commands that can be accessed from the static TabItemCommands
class.
TogglePin command
When executing the command with a given RadTabItem
as a command parameter, the item will be pinned/unpinned depending on its current state.
Execute the TogglePin command
TabItemCommands.TogglePin.Execute(null,myRadTabItem);
Close command
When executing the command with a given RadTabItem
as a command paramter, the item will be closed.
Execute the Close command
TabItemCommands.Close.Execute(null,myRadTabItem);
Special Cases
This section describes special cases where the pin and close feature behave different than expected.
Pinning items rules are not followed when multiline tabs occur and
ReorderTabRows
istrue
(default value).ReorderTabRows
makes the selected tab always on the last row so that content is as close as possible. Pinning items is not supported in this case. If you need multiline tabs and pinning set theReorderTabRows
property tofalse
.When the
AllowDragReorder
property is set totrue
the user will be able to rearrange the tabs while dragging them. When there are pinned/unpinned tab items this behavior is slightly different. You could rearrange the pinned or unpinned items while performing a dragging operation. Dragging a pinned tab item between unpinned tabs is not allowed.