をListBox追加したがありContextMenuます。内の項目の 1 つをContextMenuコマンドにバインドし、そのコマンドに渡されるパラメーターをListBoxコントロールの現在選択されている項目にしたいと考えています。これが私のxamlです:
<ListBox x:Name="selectedVascularBeds"
ItemsSource="{Binding Path=UserSelectedVascularBeds}"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DropHandler="{Binding}"
DisplayMemberPath="VascularBedName">
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove" Command="{Binding Path=RemoveSelectedVascularBedCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource
Mode=FindAncestor,
AncestorType={x:Type ListBox}},
Path=SelectedItem}"/>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>
これListBoxは、ビュー モデル オブジェクトにバインドされたユーザー コントロールの一部です。基になるオブジェクトのコマンド メソッドが呼び出されますが、渡されるパラメーターは常に null です。
CommandParameterto のバインドを単純に変更してテストした{Binding}ところ、ユーザー コントロールのデータ コンテキストがメソッドに渡されました。その結果、コマンドが機能し、パラメーターが正しく渡されていることがわかりました。ListBoxのSelectedItemプロパティにアクセスするための正しいバインディングを取得できないようです。
ヘルプ?