WPF选项卡标题应显示鼠标悬停时的菜单

时间:2015-07-08 02:28:45

标签: wpf stack-overflow mouseover

我想在Tab Header上鼠标悬停时显示菜单或上下文菜单。实际上我已经在MouseUp事件上完成了(意味着点击),但是当我将鼠标悬停在标题页上时,我遇到了困难。

Codebehind如下:

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事件,则抛出异常:

  

"An unhandled exception of type 'System.StackOverflowException' occurred in PresentationCore.dll" on cm.IsOpen= true; line.

0 个答案:

没有答案