我有一个数据表格,其中定义了以下ContextMenu:
<igDP:XamDataGrid.ContextMenu>
<ContextMenu ItemsSource="{Binding CommandViewModels}" >
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Command" Value="{Binding Command}" />
<Setter Property="CommandParameter" Value="{Binding CommandParameter}" />
<Setter Property="Header" Value="{Binding Name}" />
<Setter Property="Icon" Value="{Binding Icon}" />
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
</igDP:XamDataGrid.ContextMenu>
定义了CommandViewModel类如下:
public class CommandViewModel : ICommandViewModel
{
public CommandViewModel(string name, Image icon, ICommand command, object commandParameter = null, int index = 0)
{
Name = name;
Icon = icon;
Command = command;
CommandParameter = commandParameter;
Index = index;
}
public string Name { get; set; }
public Image Icon { get; set; }
public ICommand Command { get; set; }
public object CommandParameter { get; set; }
public int Index { get; set; }
}
当我在网格中右键单击一行时,ContextMenu的每个MenuItem都被正确地设置了样式。 MenuItem的图标、标签和命令都是预期的。 但是,应该传递给绑定到MenuItem.Command的RelayCommand的命令参数CommandViewModel.CommandParameter为空。
我相当确定绑定可用的命令参数不为空。 这是在.NET 4.0上运行的WPF应用程序。
有人遇到过这种情况吗?