Я пытаюсь получить RelayCommand, работающий с CommandParameter, работающим с использованием MVVM Light. Команда определена в моей модели viewmodel, и я хочу передать выбранный элемент ListBox в качестве параметра. Команда привязана, но параметр отсутствует. Это возможно?CommandParameter с MVVM Light
<UserControl x:Class="Nuggets.Metro.Views.EmployeeListView"
...
DataContext="{Binding EmployeeList,Source={StaticResource Locator}}">
<ListBox x:Name="lstEmployee" ItemsSource="{Binding EmployeeItems}" Style="{StaticResource EmployeeList}" Tag="{Binding EmployeeItems}">
<ListBox.ContextMenu>
<ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
<MenuItem Header="Edit item" Command="{Binding EditEmployeeCommand}" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"/>
<MenuItem Header="Delete item" Command="{Binding DeleteEmployeeCommand}" CommandParameter="{Binding PlacementTarget.SelectedItem,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"/>
</ContextMenu>
</ListBox.ContextMenu>
Это кажется логичным, но: 'System.Windows.Data Ошибка: 4: Не удается найти источник для связывания со ссылкой 'ElementName = lstEmployee. BindingExpression: Path = SelectedItem; DataItem = NULL; целевым элементом является «MenuItem» (Name = ''); target свойство «CommandParameter» (тип «Object») ' – Echilon
@ Echilon обновил мой ответ – Jehof
Удивительно, спасибо. – Echilon