2011-08-11 23 views
5

我想添加一个上下文菜单到tabitem。但只能通过点击选项卡的标题打开它。 我添加了文本菜单是这样的:Wpf - TabItem中的上下文菜单标题

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

只有当你克利克的TabItem上的标题,文本菜单中应该打开。

It should only work by right-klicking in the header

但是,如果你克利克在TabItem的另一个位置,它shouldn't显示。

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

我需要在运行时做到这一点编程。 xaml中的解决方案也可以。

回答

7

如何像:

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

谢谢,完美的作品。 –