Reputation:
I would like to pass a CommandParameter to a Command on ListBoxItem selection but can't figure out how to do it (I'm new to mvvm & commands so it may be trivial).
I tried to do this, but the CommandParameter property seems not to be available:
<ListBoxItem>
<ListBoxItem.CommandBindings>
<CommandBinding Command="{Binding OperationsCommand}"/>
</ListBoxItem.CommandBindings>
<TextBlock Text="All Items"/>
</ListBoxItem>
Upvotes: 0
Views: 676
Reputation: 1996
You can bind the selecteditem to your viewmodel directly and in setter for that item you can perform your operation.
<ListBox ItemSource="{Binding YourCollection}" SelectedItem="{Binding MyItem}"/>
Upvotes: 2