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:
- Instances of TabItemExt that need to be closed.
- 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); }