I wanted to add a context menu to tabitem. But it should be opened only by clicking on the tab title. I added Contextmenu as follows:
ContextMenu _contextMenu;
TabItem _tabItem;
_tabItem.ContextMenu = _contextMenu;
Only if you click on the TabItem header does ContextMenu need to be opened.

But if you click in another tabItem position, it should not be displayed.

I need to do this programmatically at runtime. The solution in xaml is ok too.
source
share