WPF选项卡标题应在鼠标悬停时显示菜单
我想在鼠标悬停在选项卡标题上时显示菜单或上下文菜单。实际上,我已经在MouseUp事件上这样做了(意思是单击),但当我将鼠标移到选项卡标题上时,我遇到了困难 代码隐藏如下:WPF选项卡标题应在鼠标悬停时显示菜单,wpf,stack-overflow,mouseover,Wpf,Stack Overflow,Mouseover,我想在鼠标悬停在选项卡标题上时显示菜单或上下文菜单。实际上,我已经在MouseUp事件上这样做了(意思是单击),但当我将鼠标移到选项卡标题上时,我遇到了困难 代码隐藏如下: private void tabItem_MouseUp(object sender, MouseButtonEventArgs e) { ContextMenu cm = (sender as TabItem).ContextMenu; cm.PlacementTarget = sen
private void tabItem_MouseUp(object sender, MouseButtonEventArgs e)
{
ContextMenu cm = (sender as TabItem).ContextMenu;
cm.PlacementTarget = sender as TabItem;
cm.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
cm.IsOpen = true;
}
如果我使用MouseMove或MouseEnter事件,则会引发异常:
“System.StackOverflowException类型的未处理异常”
发生在cm.IsOpen上的PresentationCore.dll中=true;行。
可能是
IsOpen
属性再次调用了tabItem\u MouseUp
?导致StackOverflowException
。是的,我知道这是原因,但我们如何解决?