<Window.Resources>
<ContextMenu x:Key="TableContextMenu">
<MenuItem Command="Copy" />
<MenuItem Header="asdasdsad" />
</ContextMenu>
<Style TargetType="{x:Type Table}">
<Setter Property="ContextMenu" Value="{StaticResource TableContextMenu}" />
</Style>
</Window.Resources>
有人有想法吗?
答案 0 :(得分:0)
知道了,你必须手动打开上下文菜单..
<Style TargetType="{x:Type TableCell}">
<EventSetter Event="ContextMenuOpening" Handler="Table_ContextMenuOpening" />
<Setter Property="ContextMenu" Value="{StaticResource TableContextMenu}" />
</Style>
在contextmenu开启处理程序中,您必须将处理的param设置为true并打开contextmenu
lastTableCell.ContextMenu.IsOpen = true;
如果上下文菜单中的命令显示为灰色:afaik这是一个错误,您必须将命令绑定直接放入XAML中的上下文菜单中
<ContextMenu x:Key="TableContextMenu">
<ContextMenu.CommandBindings>
<CommandBinding Command="{x:Static main:MainWindow.AddRowAboveCommand}"
CanExecute="CanExecuteAlways"
Executed="AddRowAbove_Executed" />
</ContextMenu.CommandBindings>
干杯