如何在TabControl中响应右键鼠标(添加一个ContextMenu就可以了),如何让在tab标签处右键菜单和在内容处右键菜单显示不同的菜单?
2007-02-05 09:35 爱车龟速兔 阅读(842) 评论(0) 编辑 收藏 举报下面的代码演示的就是这种情况 (TabAndContextMenuDemo1)
<TabControl Name ="ta1" >
<TabItem Name="backgroundcolor" Header="Choose a Background Color" Content = "Some content about background colors.">
<TabItem.ContextMenu >
<ContextMenu >
<MenuItem Header="Red" Name="testRed" Click="MyMenuHandler"/>
<MenuItem Header="Blue" Name="blue" Click="MyMenuHandler"/>
<MenuItem Header="Yellow" Name="yellow" Click="MyMenuHandler"/>
</ContextMenu>
</TabItem.ContextMenu>
</TabItem>
<TabItem Name="Item2" Header="Casf" Content = "it2">
<TabItem.ContextMenu >
<ContextMenu >
<MenuItem Header="1" Name="a" />
<MenuItem Header="2" Name="b" />
<MenuItem Header="3" Name="c"/>
</ContextMenu>
</TabItem.ContextMenu>
</TabItem>
<TabControl.ContextMenu>
<ContextMenu >
<MenuItem Header="12" Name="d" />
<MenuItem Header="sdf" Name="e" />
<MenuItem Header="void" Name="f" />
</ContextMenu>
</TabControl.ContextMenu>
</TabControl>