Category / Section
How to add the custom context menu items for TabItem in TabControlExt?
1 min read
To add the custom Context menu item in the TabControlExt, the ContextMenuItems property of TabItemExt can be used and set IsCustomTabItemContextMenuEnabled as true to enable the CustomContextMenuItem to ContextMenu. The same has been demonstrated in the following code example:
XAML:
<Window x:Class="TabControlExtContextMenu_158240.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
Title="MainWindow" Height="350" Width="525">
<Grid x:Name="Grid1">
<syncfusion:TabControlExt x:Name="TabControlExt" IsCustomTabItemContextMenuEnabled="True">
<syncfusion:TabItemExt x:Name="Tab1" Header="TabItem1">
<syncfusion:TabItemExt.ContextMenuItems>
<syncfusion:CustomMenuItem Header="Menu1"></syncfusion:CustomMenuItem>
</syncfusion:TabItemExt.ContextMenuItems>
</syncfusion:TabItemExt>
<syncfusion:TabItemExt x:Name="Tab2" Header="TabItem2">
<syncfusion:TabItemExt.ContextMenuItems>
<syncfusion:CustomMenuItem Header="Menu2"></syncfusion:CustomMenuItem>
</syncfusion:TabItemExt.ContextMenuItems>
</syncfusion:TabItemExt>
<syncfusion:TabItemExt x:Name="Tab3" Header="TabItem3">
<syncfusion:TabItemExt.ContextMenuItems>
<syncfusion:CustomMenuItem Header="Menu3"></syncfusion:CustomMenuItem>
</syncfusion:TabItemExt.ContextMenuItems>
</syncfusion:TabItemExt>
</syncfusion:TabControlExt>
</Grid>
</Window>
C#:
TabControlExt.IsCustomTabItemContextMenuEnabled = true;
CustomMenuItem item = new CustomMenuItem();
item.Header = "item1";
//Shows the Custom menu item had been added to the tab item using the ContextMenuItems property of TabItemExt.
Tab1.ContextMenuItems.Add(item);
Output:
The following screenshot shows the Custom context menu item has been added in the tab item