Articles in this section
Category / Section

How to programmatically close Tab items?

1 min read

TabItemExt can be closed programmatically by using the CloseCurrentTabItem command.

Invoke CloseCurrentTabItem command

Create an instance for the TabControlCommands.CloseCurrentTabItem command. Invoke it by calling the Execute method. Arguments of the method are:

  1. Instances of TabItemExt that need to be closed.
  2. Target control.

MainWindow.xaml

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="150"/>
        </Grid.ColumnDefinitions>
        <Button Grid.Column="1" Width="120" Height="28" Click="Button_Click"  Content="Close SelectedItem"/>                      
        <syncfusion:TabControlExt Name="tabcontrol">
            <syncfusion:TabItemExt Name="item1" Header="Item1" />
            <syncfusion:TabItemExt Name="item2" Header="Item2"/>
            <syncfusion:TabItemExt Name="item3" Header="Item3"/>
            <syncfusion:TabItemExt Name="item4" Header="Item4"/>
        </syncfusion:TabControlExt>
    </Grid>

MainWindow.xaml.cs

 private void Button_Click(object sender, RoutedEventArgs e)
 {
    RoutedCommand command = TabControlCommands.CloseCurrentTabItem;
    command.Execute(tabcontrol.SelectedItem,tabcontrol);
 }

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied