WPF - 文本菜单中TabItem的标题 [英] Wpf - Contextmenu in TabItem Header

查看:1191
本文介绍了WPF - 文本菜单中TabItem的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个文本菜单添加到TabItem的。但它应该仅通过点击选项卡的标题被打开。
我添加了文本菜单是这样的:

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;



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

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

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

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

我需要在运行时做编程。在XAML中的解决方案也是OK

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

推荐答案

如何是这样的:

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

这篇关于WPF - 文本菜单中TabItem的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆