WPF: Powiązanie MenuItem.CommandParameter ustawione na null
Mam następujące ContextMenu zdefiniowane dla mojej siatki danych:
<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>
Klasa CommandViewModel jest zdefiniowana w następujący sposób:
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; }
}
Kiedy klikam prawym przyciskiem myszy na wierszu w siatce, każdy MenuItem ContextMenu jest poprawnie stylizowany. Ikona, etykieta i polecenie MenuItem są zgodne z oczekiwaniami. Jednak parametr command, CommandViewModel.CommandParameter, który należy przekazać jako argument do RelayCommand powiązanego z MenuItem.Command, jest pusty.
Jestem pewien, że parametr polecenia dostępny dla powiązania nie jest pusty. To jest aplikacja WPF działająca na .NET 4.0.
Czy ktoś to doświadczył?