Basic Library for WPF and Silverlight | ComponentOne
WPF and Silverlight Edition Basic Library / TabControl / TabControl Features / Tab Closing
In This Topic
    Tab Closing
    In This Topic

    By default, users can't close the tabs on a C1TabControl control. You can add a close button to each tab by setting the TabItemClose property to InEachTab. This will allow users to close any tab in the control. On-tab close buttons appear as follows:

    If you prefer, you can create a global close button that will appear on the tabstrip instead of directly on the tabs. To add the global close button, you set the TabItemClose property to GlobalClose. Clicking the global close button will close the currently selected tab. The global close button appears as follows:

    To allow users to close tabs, follow one of the following methods:

    To allow users to close tabs using a universal button, add TabItemClose="GlobalClose" to <c1:C1TabControl> tab so that the markup resembles the following:

    XAML
    Copy Code
    <c1:C1TabControl TabItemClose="GlobalClose"></c1:C1TabControl>
    

    Complete the following steps:

    1. Switch to Code view.
    2. Add the following code beneath the InitializeComponent() method:
    Visual Basic
    Copy Code
    C1TabControl1.TabItemClose = GlobalClose
    

     

    C#
    Copy Code
    c1TabControl1.TabItemClose = GlobalClose;
    
    1. Run the program.

    Complete the following steps:

    1. Select the C1TabControl control.
    2. In the Properties window, click the TabItemClose drop-down arrow and select GlobalClose from the list.

     

    To prevent a user from closing a particular tab, use one of the following methods:

    To prevent a user from closing a tab, add CanUserClose="False" to the <c1:C1TabItem> tag of the tab you want to prevent users from closing. The XAML will resemble the following:

    XAML
    Copy Code
    <c1:C1TabItem CanUserClose="False"></c1:C1TabControl>
    

    Complete the following steps:

    1. Switch to Code view.
    2. Add the following code beneath the InitializeComponent() method:
    Visual Basic
    Copy Code
    C1TabItem1.CanUserClose = False
    

     

    C#
    Copy Code
    c1TabItem1.CanUserClose = false;
    
    1. Run the program.

    Complete the following steps:

    1. Select the tab that you wish to prevent users from closing.
    2. In the  Properties window, clear the CanUserClose check box.