I have a ListBox that I have added a context menu to. I want one of the items in the context menu to be bound to a command and I want the parameter passed to that command to be the currently selected item of the ListBox control. Here's my 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>
This ListBox is part of a user control that is bound to a view model object. My command method on the underlying object gets called but the parameter passed in is always null.
I have tested changing the binding of the CommandParameter to simply "{Binding}" which results in the user control's data context being passed into my method - so I know that the command is working and passes parameters correctly I just can't seem to get the correct binding to access the ListBox's SelectedItem property.
Help?