Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wpf - Contextmenu in TabItem Header

I wanted to add a contextmenu to a tabitem. But it should only be opened by clicking on the header of the tab. I added the Contextmenu like this:

ContextMenu _contextMenu;
TabItem _tabItem;
//Initialize the components
_tabItem.ContextMenu = _contextMenu;

Only if you klick on the header of the TabItem, the ContextMenu should be opened.

It should only work by right-klicking in the header

But if you klick at another position of the tabItem, it shouldn´t be displayed.

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

I need to do that programmatically during the runtime. A solution in xaml is ok, too.

like image 985
Andre Gross Avatar asked Aug 11 '11 10:08

Andre Gross


1 Answers

How about something like:

_tabItem.Header = new ContentControl
                 {
                     Content = "StartPage",
                     ContextMenu = _contextMenu
                 };
like image 163
Matt Hamilton Avatar answered Oct 22 '22 12:10

Matt Hamilton