我有一个带有上下文菜单的按钮,但是我可以将ContextMenuOpening事件触发.
<Button Name="a_button"
ContextMenu="{StaticResource MyContextMenu}"
ContextMenuOpening="MyContextMenu_Opening" >
</Button>
private void MyContextMenu_Opening(object sender, ContextMenuEventArgs e)
{
// doesnt get here.
}
任何想法如何使这项工作?
谢谢.
解决方法:
我刚刚检查了您的代码,它运行完美.
这是我的完整XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<ContextMenu x:Key="MyContextMenu">
<MenuItem Header="Send" />
</ContextMenu>
</Window.Resources>
<Grid>
<Button Name="a_button"
ContextMenu="{StaticResource MyContextMenu}"
ContextMenuOpening="MyContextMenu_Opening" >
</Button>
</Grid>
</Window>
和* .cs:
private void MyContextMenu_Opening(object sender, ContextMenuEventArgs e)
{
}