I have the following ContextMenu defined for my data grid:
<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>
A CommandViewModel class is defined as follows:
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; }
}
When I right click on a row in the grid, each MenuItem of the ContextMenu is correctly styled. The icon, label and command of the MenuItem is as expected. However, the command parameter, CommandViewModel.CommandParameter, that should be passed as argument to the RelayCommand bound to MenuItem.Command is null.
I am fairly certain that the command parameter available for the binding is not null. This is WPF application running on .NET 4.0.
Anyone experienced this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…