开发者

Wpf - Contextmenu in TabItem Header

开发者 https://www.devze.com 2023-03-27 01:44 出处:网络
I wanted to add a contextmenu to a tabitem. But it should only be opened by clicking on the header of the tab.

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;
/开发者_StackOverflow社区/Initialize the components
_tabItem.ContextMenu = _contextMenu;

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

Wpf - Contextmenu in TabItem Header

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

Wpf - Contextmenu in TabItem Header

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


How about something like:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号