Version

ShowTabHeaderCloseButton Property

Returns or sets a boolean indicating whether a close button should be displayed within the tab item area of the control
Syntax
'Declaration
 
Public Property ShowTabHeaderCloseButton As Boolean
public bool ShowTabHeaderCloseButton {get; set;}
Example
The following demonstrates how the XamtabControl supports the closing (and un-closing) of tabs.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();

        // Allow tab closing by default.
        this.xamTabControl1.AllowTabClosing = true;
        
        // Note: tab closing can be overriden on each TabItemEx by setting its AllowClosing
        // property, e.g.
        ((TabItemEx)this.xamTabControl1.Items[0]).AllowClosing = false;

        // Show a close button in the tab header area that will close the selected tab
        this.xamTabControl1.ShowTabHeaderCloseButton = true;

        // Show a close button in the TabItemEx if the tab is selected
        // or if the mouse is over it.
        this.xamTabControl1.TabItemCloseButtonVisibility = TabItemCloseButtonVisibility.WhenSelectedOrHotTracked;
        
        // Note: tab item close button visibility can be overriden on each TabItemEx by 
        // setting its CloseButtonVisibility property, e.g.
        ((TabItemEx)this.xamTabControl1.Items[2]).CloseButtonVisibility = TabItemCloseButtonVisibility.Hidden;

        // Wire the Closing event for a specific tab. Setting Cancel to true inside the event will 
        // prevent the tab from being closed
        ((TabItemEx)this.xamTabControl1.Items[1]).Closing += new EventHandler<TabClosingEventArgs>(tabItemEx2_Closing);

        // Note: when the XamTabControl closes a tab it leaves it in the Items
        // collection and just sets the tab item's Visibility to 'Collapsed'.
        // Therefore, to unclose a tab set its Visibility property back to 'Visible'
        // (see the btnUncloseAllTabs_Click event handler below).
    }

    private void tabItemEx2_Closing(object sender, TabClosingEventArgs e)
    {
        // Setting Cancel to true will prevent the tab from being closed
        e.Cancel = true;
    }

    private void btnUncloseAllTabs_Click(object sender, RoutedEventArgs e)
    {
        int count = this.xamTabControl1.Items.Count;

        ItemContainerGenerator generator = this.xamTabControl1.ItemContainerGenerator;

        // loop over all the tab items in the XamTabControl and set their
        // Visibility property to 'Visibile' to un-close them.
        for (int i = 0; i < count; i++)
        {
            TabItem tabItem = generator.ContainerFromIndex(i) as TabItem;

            if (tabItem != null)
                tabItem.Visibility = Visibility.Visible;

        }
    }
<Window x:Class="XamTabControl_cs.Window1"
    
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    
Title="Window1" Height="300" Width="647" 
    
xmlns:igThemes="http://infragistics.com/Themes" 
    
xmlns:igWindows="http://infragistics.com/Windows">
    
<Grid >
        
<igWindows:XamTabControl Name="xamTabControl1" 
             
Margin="19,50,10,12"
             
AllowTabClosing="True"
             
ShowTabHeaderCloseButton="True"
             
TabItemCloseButtonVisibility="WhenSelectedOrHotTracked">

            
<igWindows:TabItemEx Header="tabItemEx1" Name="tabItemEx1" AllowClosing="false">
                
<Grid /> <!-- tab item content goes here -->
            
</igWindows:TabItemEx>

            
<igWindows:TabItemEx Header="tabItemEx2" Name="tabItemEx2" Closing="tabItemEx2_Closing">
                
<Grid /> <!-- tab item content goes here -->
            
</igWindows:TabItemEx>

            
<igWindows:TabItemEx Header="tabItemEx3" Name="tabItemEx3" CloseButtonVisibility="Hidden">
                
<Grid /> <!-- tab item content goes here -->
            
</igWindows:TabItemEx>

        
</igWindows:XamTabControl>

        
<Button Name="btnUncloseAllTabs" Height="32" HorizontalAlignment="Left" Margin="300,12,0,0" VerticalAlignment="Top" Width="150" 
                    
Click="btnUncloseAllTabs_Click">Unclose all tabs</Button>
    
</Grid>
</Window>
Imports Infragistics.Windows.Controls
Imports Infragistics.Windows.Controls.Events
Imports System.Windows.Controls.Primitives
Imports System.Diagnostics
Imports System.Windows

Class Window1

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        ' Allow tab closing by default.
        Me.XamTabControl1.AllowTabClosing = True

        ' Note: tab closing can be overriden on each TabItemEx by setting its AllowClosing
        ' property, e.g.
        TryCast(Me.XamTabControl1.Items(0), TabItemEx).AllowClosing = False

        ' Show a close button in the tab header area that will close the selected tab
        Me.XamTabControl1.ShowTabHeaderCloseButton = True

        ' Show a close button in the TabItemEx if the tab is selected
        ' or if the mouse is over it.
        Me.XamTabControl1.TabItemCloseButtonVisibility = TabItemCloseButtonVisibility.WhenSelectedOrHotTracked

        ' Note: tab item close button visibility can be overriden on each TabItemEx by 
        ' setting its CloseButtonVisibility property, e.g.
        TryCast(Me.XamTabControl1.Items(2), TabItemEx).CloseButtonVisibility = TabItemCloseButtonVisibility.Hidden

        Dim tab As TabItemEx = TryCast(Me.XamTabControl1.Items(1), TabItemEx)

        ' Wire the Closing event for a specific tab. Setting Cancel to true inside the event will 
        ' prevent the tab from being closed
        AddHandler tab.Closing, AddressOf tabItem_Closing

        ' Note: when the XamTabControl closes a tab it leaves it in the Items
        ' collection and just sets the tab item's Visibility to 'Collapsed'.
        ' Therefore, to unclose a tab set its Visibility property back to 'Visible'
        ' (see the btnUncloseAllTabs_Click event handler below).

    End Sub

    Private Sub tabItem_Closing(ByVal sender As Object, ByVal e As TabClosingEventArgs)
        ' Setting Cancel to true will prevent the tab from being closed
        e.Cancel = True
    End Sub

    Private Sub btnUncloseAllTabs_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim count As Int32 = Me.XamTabControl1.Items.Count
        Dim generator As ItemContainerGenerator = Me.XamTabControl1.ItemContainerGenerator
        Dim tabItem As TabItem

        ' loop over all the tab items in the XamTabControl and set their
        ' Visibility property to 'Visibile' to un-close them.
        For i As Int32 = 0 To count - 1
            tabItem = TryCast(generator.ContainerFromIndex(i), TabItem)

            If Not tabItem Is Nothing Then
                tabItem.Visibility = Visibility.Visible
            End If
        Next

    End Sub
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also