Wpf - Contextmenu in the TabItem header

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;
//Initialize the components
_tabItem.ContextMenu = _contextMenu;

Only if you click on the TabItem header does ContextMenu need to be opened.

It should only work by right-klicking in the header

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

If you don´t klick on the header, it shouldn´t displayed

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

+5
source share
1 answer

How about something like:

_tabItem.Header = new ContentControl
                 {
                     Content = "StartPage",
                     ContextMenu = _contextMenu
                 };
+7
source

All Articles