MVVM Light을 사용하여 작동하는 CommandParameter로 작업하는 RelayCommand를 가져 오려고합니다. 명령은 내 viewmodel에 정의되어 있으며 선택한 ListBox 항목을 매개 변수로 전달하려고합니다. 명령이 바인드되었지만 매개 변수가 바인드되지 않았습니다. 이것이 가능한가?MVVM Light이있는 CommandParameter
<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 = ''); 대상 속성은 'CommandParameter'('Object'유형)입니다. – Echilon
@Echilon 전 대답을 업데이트했습니다 – Jehof
감사합니다. – Echilon